/[openfoncier]/trunk/trt/export_sitadel.php
ViewVC logotype

Contents of /trunk/trt/export_sitadel.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (show annotations)
Mon Jul 18 15:30:49 2011 UTC (13 years, 6 months ago) by fraynaud
File size: 47896 byte(s)
maj trt et img 3.0


1 <?php
2 // $Id: export_sitadel.php,v 1.20 2010-11-15 14:50:40 fraynaud Exp $
3 /*
4 transfert de dossier à SITADEL
5 realisé ville arles par fr+jlb
6 voir parametrage trt/sitadel.inc
7 */
8 function maj($val) {
9 $val = strtoupper($val);
10 $val=str_replace(chr(195), "", $val); // supprime le premier code des accents en UTF-8
11 $s = array('/[âàäÀ]/', '/[éêèëÉÈ]/', '/[îï]/', '/[ôöÔ]/', '/[ûùü]/', '/[çÇ]/', '/\'|\"|^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\-\s\r/');
12 $r = array('A', 'E', 'I', 'O', 'U', 'C', ' ');
13 $val = preg_replace($s , $r, $val);
14 return $val;
15 }
16 require_once "../obj/utils.class.php";
17 $f = new utils(NULL, "export", _("export SITADEL"), "ico_reqmo.png", "export");
18 $f->addHTMLHeadJs(array("../js/script.js"));
19 // GET
20 if (isset ($_GET['validation'])){
21 $validation=$_GET['validation'];
22 }else{
23 $validation=0;
24 }
25 if (isset ($_GET['idx'])){
26 $idx=$_GET['idx'];
27 }else{
28 $idx=0;
29 }
30 /**
31 * Description de la page
32 */
33 $description = _("Cette page vous permet de Transmettre les dossiers suivant la procedure SITADEL");
34 $f->displayDescription($description);
35 //controle
36 $DEBUG=1;
37 $x=array();
38 $cpt_depot=0;
39 $cpt_decision=0;
40 $cpt_suivi1=0;
41 $cpt_suivi2=0;
42 $cpt_transfert=0;
43 $cpt_modificatif=0;
44 include("sitadel.inc");
45 // parametres collectivite
46 $departement =$f->collectivite["departement"];
47 $region =$f->collectivite["region"];
48 // =============================================================================
49 // validation = 0
50 // =============================================================================
51 if($validation==0){
52 $validation=1;
53 echo "<table class='dossier' width='95%'>";
54 echo "<tr class='dossier'><td colspan=2><br><center>";
55 echo "<form method=\"POST\" action=\"export_sitadel.php?validation=".$validation."\" name=f1>";
56 echo "DATE DEBUT de dépôt ";
57 echo "<input type='text' name='datedebut' id=\"datedebut\" value=\"";
58 echo "\" size=\"15\" class=\"champFormulaire datepicker\" onchange='fdate(this)' onkeyup=\"\" onclick=\"\" />";
59 echo " DATE FIN de dépôt ";
60 echo "<input type='text' name='datefin' id=\"datefin\" value=\"";
61 echo "\" size=\"15\" class=\"champFormulaire datepicker\" onchange='fdate(this)' onkeyup=\"\" onclick=\"\" />";
62 echo "Numero d ordre d envoi: <SELECT name='numero'";
63 for($i=1;$i<11;$i++){
64 echo "<option value ='".$i."'>".$i."</option>";
65 }
66 echo "</select>";
67 echo "<br><br><input type='submit' value='export SITADEL'>";
68 echo "<br><br></form>";
69
70 echo "</td></tr>";
71 echo "</table>";
72
73 }else { // ===================== extraction =================================
74
75 $correct=true;
76 $longueurenregistrement= 0 ; // a calculer
77 $decision="";
78 $cpt_decisionsuivantdepot=0;
79 // entete
80 $nombreenregistrement=1; // l entete est comptée dans le nombre enregistrement
81 if($_POST["datedebut"]=="") $correct=false;
82 if($_POST["datefin"]=="") $correct=false;
83 if ($correct==true){ // ***
84 // ==================================================================================
85 // evenement de depot sur une période *** DEPOT ***
86 // ==================================================================================
87 $sql= "select date_depot, annee, dossier.dossier, dossier.date_decision, demandeur_civilite, dossier.nature,demandeur_categorie,
88 categorie_demandeur.libelle as categorie_libelle,demandeur_nom,demandeur_societe,demandeur_adresse,
89 demandeur_ville,demandeur_cp,demandeur_telephone,demandeur_email,delegataire, delegataire_nom,
90 delegataire_civilite, delegataire_adresse, delegataire_cp, delegataire_ville,parcelle, terrain_numero,
91 terrain_numero_complement,terrain_adresse,terrain_adresse_complement, terrain_ville, terrain_cp,
92 architecte from dossier
93 left join categorie_demandeur on demandeur_categorie= categorie_demandeur.categorie_demandeur";
94 $sql.= " where date_depot>='".substr($_POST["datedebut"],6,4).
95 "-".substr($_POST["datedebut"],3,2)."-".
96 substr($_POST["datedebut"],0,2)."'";
97 $sql.= " AND date_depot<='".substr($_POST["datefin"],6,4).
98 "-".substr($_POST["datefin"],3,2)."-".
99 substr($_POST["datefin"],0,2)."'";
100 $sql.= " AND (nature='PC' or nature = 'PD' or nature = 'PA' or nature = 'DP')";
101 $sql.= " and types != 'Transfert'";
102 // pour modificatif faire un enregistrement depot
103 echo "<br><font style='background-color:#ffffff;border : 1px solid #000000'>DEPOT</font> ".$sql."";
104 $res = $f->db -> query ($sql);
105 $f->isDatabaseError($res);
106 $export="";
107 $bl="";
108 $depot="";
109 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
110 // cas depot page 10
111 $nombreenregistrement++;
112 $cpt_depot++;
113 // ======================
114 // entete depot du permis
115 // ======================
116 // sitadel : mouv|typpermis|equivalence|dep|commune|andepnumpc|indmod
117 // typepermis = dossier.nature
118 // annee = dossier.annee
119 // andepnumpc|indmod = substr dossier.dossier
120 $depot.="DEPOT|".$row['nature']."||".$departement."|".$commune."|".$row['annee']."|".substr($row['dossier'],4,5)."|".substr($row['dossier'],9,2)."|";
121 // ==================
122 // data du depot p 13
123 // ==================
124 // etat civil demandeur
125 // codemo|
126 if($row['demandeur_categorie']==9 or $row['demandeur_categorie']=="")
127 $codemo=1;// personne physique
128 else
129 $codemo=2;// personne morale
130 $depot.=$codemo."|"; // 1 personne physique ; 2 sinon
131 // openfoncier civilite (5/8 ok), nom (80/30-> substr), societe (80/50->substr)
132 // civpart|prenompart|nompart|denopm|rspm|siret|catjur|civrep|prenomrep|nomrep|
133 // suivant codemo = 1 (personne physique) ou 2 (personne morale)
134 // demandeur_civilite n est pas normalise Madame ou Monsieur
135 if($codemo==1){
136 // civpart|*prenompart*|nompart||||||
137 $depot.= "||";
138 $depot.= maj(substr($row['demandeur_nom'],0,30))."||||||||";
139 }else{
140 //denopm|rspm|*siret*|*catjur*|civrep|*prenomrep*|nomrep|
141 // $depot.="|||".maj(substr($row['demandeur_societe']),0,50)."|"; // ERREUR *** a remettre
142 $depot.=maj(substr($row['categorie_libelle'],0,30))."|";
143 $depot.="||||".
144 maj(substr($row['demandeur_nom'],0,30))."|"; // pas de prenom
145 }
146 // openfoncier : adresse (80/ 26+38 -> substr sur 2 zones) - cp (5/5 OK) - ville (30/36 -> OK)
147 // *numvoiemo*|*typvoiemo*|libvoiemo|lieuditmo(+)|communemo|codposmo|*bpmo*|*cedexmo*|*paysmo*|*divetermo|
148 $depot.= "||".maj(substr($row['demandeur_adresse'],0,26))."|".
149 maj(substr($row['demandeur_adresse'],26,38))."|";
150 $depot.= maj($row['demandeur_ville'])."|".$row['demandeur_cp']."|||||"; // *** +2
151 // ===================
152 // delegataire / tiers
153 // ===================
154 // openFoncier civilite (non normalise monsieur/madame), nom (80/30 substr)
155 // openfoncier : adresse (80/ 26+38 -> substr sur 2 zones) - cp (5/5 OK) - ville (30/32 -> OK)
156 // sitadel civtiers|*prenomtier*|nomtier|*numvoietiers*|*typvoietiers*|
157 // libvoietiers|lieudittier|communetier|codpostier
158 // |*bptier*|*cedextier*|*paystier*|*divtertier*|
159 if($row['delegataire']=='Oui'){
160 $depot.= "|"; // *** 1
161 $depot.="|".maj(substr($row['delegataire_nom'],0,30))."|";
162 $depot.= "||".maj(substr($row['delegataire_adresse'],0,26))."|".
163 maj(substr($row['delegataire_adresse'],26,38))."|";
164 $depot.= maj($row['delegataire_ville'])."|".$row['delegataire_cp']."|||||"; // *** 1
165 }else{
166 $depot.= "|||||||||||||"; // *** 13 |
167 }
168 // openfoncier telephone (14/20 ok) email (40/50)
169 // sitadel : telmo|melmo|
170 $depot.= $row['demandeur_telephone']."|";
171 $depot.= $row['demandeur_email']."|";
172 // sitadel: suivi
173 if($row['delegataire']=='Oui'){
174 $depot.= "1|";
175 }else{
176 $depot.= "0|";
177 }
178 // ==================
179 // adresse du terrain
180 // ==================
181 // openfoncier numero (4/5 substr), adresse(80, 26 +38 -> substr), complement (non utilise (80)), cp (5/5 ok), ville (30/32 ok)
182 // terrain_complement ????
183 // sitadel : numvoiete|*typvoiete*|libvoiete|lieudite|communete|codposte|*bpte*|*cedexte*|
184 $depot.= substr($row['terrain_numero'],0,4)."|";
185 $depot.= "|".maj(substr($row['terrain_adresse'],0,26))."|".
186 maj(substr($row['terrain_adresse'],26,38))."|";
187 $depot.= maj($row['terrain_ville'])."|";
188 $depot.= $row['terrain_cp']."|";
189 $depot.= "||";
190 // ========
191 // parcelle
192 // ========
193 // cadastre 3 parcelles + 3 sections
194 // openfoncier = 1 seule parcelle (6/3+5)
195 // sitadel : scadastre1|ncadastre1|*scadastre2*|*ncadastre2*|*scadastre3*|*ncadastre3*|
196 $depot.= substr($row['parcelle'],0,2)."|";
197 $depot.= substr($row['parcelle'],2,4)."|||||";
198 // ===========================
199 // contrat maison individuelle
200 // ===========================
201 // sitadel : contrat|
202 // openfoncier : non renseigne
203 $depot.= "|";
204 // ==========
205 // architecte
206 // ==========
207 // sitadel : architecte|
208 // openfoncier : architecte >0
209 if($row['architecte']>0)
210 $depot.= "1|";
211 else
212 $depot.= "0|";
213 // =====================
214 // utilisation data cnil
215 // ======================
216 // sitadel : cnil
217 // openfoncier : non renseigne
218 $depot.= "1";
219 // fin d enregistrement depot
220 $depot.="\n";
221
222 // cas d un depot sans decision: ajout d un enregistrement decision en cours
223 if ($row['date_decision']== '0000-00-00' or !isset($row['date_decision'])){
224 $nombreenregistrement++;
225 $cpt_decisionsuivantdepot++;
226 $decision.="DECISION|".$row['nature']."||".$departement."|".$commune."|".
227 $row['annee']."|".
228 substr($row['dossier'],4,5)."|".substr($row['dossier'],9,2)."|"."1|0||\n";
229 }
230 }// end while depot
231
232 if($DEBUG==1){
233 $temp=explode("\n",$depot);
234 $temp1=sizeof($temp)-1;
235 for($g=0;$g<$temp1;$g++){
236 $temp2=array();
237 $temp2 = explode("|",$temp[$g]);
238 $v=$g+1;
239 echo "<br><br>depot : ".$v." ============== <br>";
240 for($k=0;$k<sizeof($temp2);$k++){
241 $t=$k+1;
242 echo $t." : ".$temp2[$k]."<br>";
243 }
244 }
245 }// end debug
246 // $res -> free ();
247 // ==================================================================================
248 // evenement de decision sur une période *** DECISION ***
249 // ==================================================================================
250 $sql= "select annee, dossier.dossier, dossier.nature,
251 terrain_surface, amenagement, travaux.libelle as travaux_libelle,
252 shon,logement_nombre, piece_nombre,
253 date_decision, avis.sitadel as avis_sitadel, avis.sitadel_motif as avis_sitadel_motif,
254 travaux.codelascot as lascot
255 from dossier left join travaux on dossier.travaux=travaux.travaux
256 left join avis on avis.avis= dossier.avis";
257 $sql.= " where date_decision>='".substr($_POST["datedebut"],6,4).
258 "-".substr($_POST["datedebut"],3,2)."-".
259 substr($_POST["datedebut"],0,2)."'";
260 $sql.= " AND date_decision<='".substr($_POST["datefin"],6,4).
261 "-".substr($_POST["datefin"],3,2)."-".
262 substr($_POST["datefin"],0,2)."'";
263 $sql.= " AND (dossier.nature='PC' or dossier.nature = 'PD' or dossier.nature = 'PA' or dossier.nature = 'DP')";
264 $sql.= " AND types != 'Modificatif'";
265 echo "<BR><br><font style='background-color:#ffffff;border : 1px solid #000000'>DECISION</font> ".$sql;
266 $res = $f->db -> query ($sql);
267 $f->isDatabaseError($res);
268 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
269 $nombreenregistrement++;
270 $cpt_decision++;
271 // Decision GROUPE 1
272 // sitadel : mouv|typpermis|equivalence|dep|commune|andepnumpc|indmod
273 $decision.="DECISION|".$row['nature']."||".$departement."|".$commune."|".$row['annee']."|".substr($row['dossier'],4,5)."|".substr($row['dossier'],9,2)."|";
274 // sitadel : collectivite|natdec|datedec|motifann
275 $decision.= '1|'; // au nom de la commune
276 // zone supplementaire dans avis
277 // ALTER TABLE `avis` ADD `sitadel_motif` VARCHAR( 1 ) NOT NULL ;
278 // 0 à 8
279 $decision.= $row['avis_sitadel']."|";
280 // date au format francais 8 caracteres
281 $decision.= substr($row['date_decision'],8,2).''.substr($row['date_decision'],5,2)."".substr($row['date_decision'],0,4)."|";
282 // Motif d annulation
283 // zone supplementaire dans avis;
284 // ALTER TABLE `avis` ADD `sitadel_motif` VARCHAR( 1 ) NOT NULL ;
285 $decision.= $row['avis_sitadel_motif'];
286 // ==================================================
287 // si decision favorable, expresse ou tacite GROUPE 2
288 // ==================================================
289 //avis sitadel
290 if($row['avis_sitadel']==2
291 or $row['avis_sitadel']==4
292 or $row['avis_sitadel']==5){
293 // renseignement du groupe 2 ***
294 //sitadel : terrain|lotissement|zac|afu|libnattrav|natproj|
295 $decision.= "|".floor($row['terrain_surface'])."|";
296 if($row['amenagement']!='')
297 $decision.= "1|";
298 else
299 $decision.= "0|";
300 $decision.= "0|0|"; // zac afu -> non renseignee
301 $decision.= maj($row['travaux_libelle'])."|";
302 // aout 2010 ????????????????? $decision.= "0|";
303 if($row['lascot']=='1'
304 or $row['lascot']=='2'
305 or $row['lascot']=='3')
306 $decision.= $row['lascot']."|"; // natproj 1:construction 2:extension ou 3:surelevation
307 else
308 $decision.= "|";
309 // natdp|nattrav|*annexe*|*nivmax* =========================
310 //natdp
311 $natdp='00000';
312 if($row['lascot']=='1') $natdp="10000"; // nouvelle construction
313 if($row['lascot']=='2') $natdp="01000"; // travaux sur construction existante
314 if($row['lascot']=='3') $natdp="01000"; //
315 if($row['lascot']=='X') $natdp="00001"; // cloture
316 $decision.= $natdp."|";
317 // nattrav
318 $nattrav = "0000";
319 if($row['lascot']=='2') $nattrav="1000";
320 if($row['lascot']=='3') $nattrav="0100";
321 $decision.= $nattrav."|";
322 // annexe non renseigner defaut 00000
323 $decision.= "00000|";
324 //nivmax non saisi
325 // ajout nivmax aout 2010
326 $decision.="|";
327 // S H O N / DESTINATION ========================================
328 //shonant1 - shonnant9|shondem1 à 9| shonanttr1 à 9| shonprojtr 1 à 9|shoncr1 a 9 |shon2cr1 a 9
329 // 1 habitation, 2 hotel , 3 bureau ... 9 ...
330 // les shon sont exprimees sans decimales
331 $decision.= "|||||||||";// shon avant travaux -> non renseigne
332 // table destination
333 $sql1="select destination, shon from destination_shon where dossier = '". $row['dossier']."'";
334 $res1 = $f->db -> query ($sql1);
335 $f->isDatabaseError($res1);
336 //
337 $tmpPD = array(); // shon existante demolie
338 for($i=0;$i<=9;$i++)
339 {
340 $tmpPD[$i]='';
341 }
342 //
343 $tmplascot4 = array(); // shon changement de destination
344 for($i=0;$i<=9;$i++)
345 {
346 $tmplascot4[$i]='';
347 }
348 //
349 $tmplascot1 = array(); // shon nouvellement construite
350 for($i=0;$i<=9;$i++)
351 {
352 $tmplascot1[$i]='';
353 }
354 //
355 $tmplascot2 = array(); // shon cree par transformation
356 for($i=0;$i<=9;$i++)
357 {
358 $tmplascot2[$i]='';
359 }
360 while ($row1=& $res1->fetchRow(DB_FETCHMODE_ASSOC)){
361 // shonprojtr1 a 9 / shoncr1 a 9 /
362 if($row['nature']== 'PD') {
363 $tmpPD[$row1['destination']] = $row1['shon']; // shon existante demolie -> a remplir
364 }
365 if($row['lascot']== '4') {
366 $tmplascot4[$row1['destination']] = $row1['shon'];// shon changement de destination -> a remplir
367 }
368 if($row['lascot']== '1'){
369 $tmplascot1[$row1['destination']] = $row1['shon'];// shon nouvellement construite -> a remplir
370 }
371 if($row['lascot']== '2') {
372 $tmplascot2[$row1['destination']] = $row1['shon'];// shon cree par transformation -> a remplir
373 }
374 }
375 // shon existante demolie -> a remplir
376 for($i=1;$i<=9;$i++)
377 {
378 $decision.=$tmpPD[$i].'|';
379 }
380 //
381 $decision.= "|||||||||";// shon supprimmee par changement de destination -> non renseigne
382 //
383 //$row['lascot']== '4' shon changement de destination
384 for($i=1;$i<=9;$i++)
385 {
386 $decision.=$tmplascot4[$i].'|';
387 }
388 //shon nouvellement construite
389 for($i=1;$i<=9;$i++)
390 {
391 $decision.=$tmplascot1[$i].'|';
392 }
393 //shon cree par transformation
394 for($i=1;$i<=9;$i++)
395 {
396 $decision.=$tmplascot2[$i].'|';
397 }
398 // fin destination_shon ====================================
399 // cpublic : non renseignee N par defaut
400 // O/N transport/enseignement/sante/social/special/culture
401 $decision.= "000000"; //* supp|
402 // nblogdem
403 $decision.= "|".$row['logement_nombre'];
404 // nbmaison : nombre de maison
405 $decision.= "|";
406 // nblogcoll : nombre de logement collectif
407 $decision.= "|";
408 // nbtotlog : nombre de logement total
409 $decision.= "|";
410 // natres : nature des residences
411 // O/N 1=ages, 2=etudiant, 3=tourisme, 4=hotel, 5=social, 6= handicap, 7=autres
412 $decision.= "|0000000";
413 // libres= si autre residence (long max 1000 c)
414 $decision.= "|";
415 // util : O/N personnel, principale, secondaire, vente, location
416 $decision.= "|00000";
417 //chambres
418 $decision.= "|";
419 // nb logement sociaux
420 $decision.= "|";
421 // nb logt financt aides
422 $decision.= "|";
423 // nb de logt pret a taux 0
424 $decision.= "|";
425 // nb de logt finances autrt
426 $decision.= "|";
427 // nb pieces en maison individuelle
428 $decision.= "|".$row['piece_nombre']; // voir si 0
429 // chambre (num capacite accueil locaux hebergement)
430 $decision.= "|";
431 // nb de logement 1piece
432 $decision.= "|";
433 // nb de logement 2 pieces
434 $decision.= "|";
435 // nb de logement 3 pieces
436 $decision.= "|";
437 // nb de logement 4 pieces
438 $decision.= "|";
439 // nb de logement 5 pieces
440 $decision.= "|";
441 // nb de logement 6 pieces
442 $decision.= "";
443 }// fin decision favorable
444 $decision.="\n";
445 } // end while decision
446 if($DEBUG==1){
447 $temp=explode("\n",$decision);
448 $temp1=sizeof($temp)-1;
449 for($g=0;$g<$temp1;$g++){
450 $temp2=array();
451 $temp2 = explode("|",$temp[$g]);
452 $v=$g+1;
453 echo "<br><br>decision : ".$v." ============== <br>";
454 for($k=0;$k<sizeof($temp2);$k++){
455 $t=$k+1;
456 echo $t." : ".$temp2[$k]."<br>";
457 }
458 }
459 } // fin debug decision
460 // ==================================================================================
461 // suivi DOC *** suivi DOC ***
462 // ==================================================================================
463 // Evenement declancheur DATE OUVERTURE DE CHANTIER
464 $sql= "select annee, dossier.dossier, dossier.nature, annee,
465 date_chantier, shon
466 from dossier ";
467 $sql.= " where date_chantier>='".substr($_POST["datedebut"],6,4).
468 "-".substr($_POST["datedebut"],3,2)."-".
469 substr($_POST["datedebut"],0,2)."'";
470 $sql.= " AND date_chantier<='".substr($_POST["datefin"],6,4).
471 "-".substr($_POST["datefin"],3,2)."-".
472 substr($_POST["datefin"],0,2)."'";
473 echo "<BR><br><font style='background-color:#ffffff;border : 1px solid #000000'>SUIVI</font> ".$sql;
474 // faut il en faire suivi 1 et suivi 2 ou dans une meme requete
475 $res = $f->db -> query ($sql);
476 $f->isDatabaseError($res);
477 $suivi1="";
478 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
479 $nombreenregistrement++;
480 $cpt_suivi1++;
481 // sitadel : mouv|typpermis|equivalence|dep|commune|andepnumpc|indmod
482 // typepermis = dossier.nature
483 // annee = dossier.annee
484 // andepnumpc|indmod = substr dossier.dossier
485 $suivi1.="SUIVI|".$row['nature']."||".$departement."|".$commune."|".$row['annee']."|".
486 substr($row['dossier'],4,5)."|".substr($row['dossier'],9,2)."";
487 // datereoc date de chantier
488 //|datereoc
489 //echo $row['date_chantier']."****************************";
490 $suivi1.="|".substr($row['date_chantier'],8,2).substr($row['date_chantier'],5,2).substr($row['date_chantier'],0,4); // *** au format francais
491 //|nblogoc|nbmaisoc|nbcolloc
492 $suivi1.="|||";
493 //|shonoc
494 $suivi1.="|".floor($row['shon']); // ok *** enlever les decimales
495 //|finisoc|finaaoc|finptzoc|finafoc|indoc
496 $suivi1.="|||||";
497 $suivi1.="||||||||||||"; // achevement
498 $suivi1.="\n";
499 }// fin while doc
500
501 if($DEBUG==1){
502 $temp=explode("\n",$suivi1);
503 $temp1=sizeof($temp)-1;
504 for($g=0;$g<$temp1;$g++){
505 $temp2=array();
506 $temp2 = explode("|",$temp[$g]);
507 $v=$g+1;
508 echo "<br><br> DOC : ".$v." ============== <br>";
509 for($k=0;$k<sizeof($temp2);$k++){
510 $t=$k+1;
511 echo $t." : ".$temp2[$k]."<br>";
512 }
513 }
514 } // fin debug
515 // ==================================================================================
516 // suivi *** suivi DAT ***
517 // ==================================================================================
518 // element declancheur : DATE ACHEVEMENT DE TRAVAUX
519 $sql= "select annee, dossier.dossier, dossier.nature, annee,
520 date_achevement, shon,date_chantier,dossier.etat
521 from dossier ";
522 $sql.= " where date_achevement>='".substr($_POST["datedebut"],6,4).
523 "-".substr($_POST["datedebut"],3,2)."-".
524 substr($_POST["datedebut"],0,2)."'";
525 $sql.= " AND date_achevement<='".substr($_POST["datefin"],6,4).
526 "-".substr($_POST["datefin"],3,2)."-".
527 substr($_POST["datefin"],0,2)."'";
528 echo "<BR><font style='background-color:#ffffff;border : 1px solid #000000'>SUIVI</font> ".$sql;
529 // ou dat ???
530 // ***
531 $res = $f->db -> query ($sql);
532 if (DB :: isError ($res))
533 die ($res -> getDebugInfo ()." Erreur ".$sql);
534 else
535 {
536 $cpt_suivi2=0;
537 $suivi2="";
538 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
539 $nombreenregistrement++;
540 $cpt_suivi2++;
541 // sitadel : mouv|typpermis|equivalence|dep|commune|andepnumpc|indmod
542 // typepermis = dossier.nature
543 // annee = dossier.annee
544 // andepnumpc|indmod = substr dossier.dossier
545 $suivi2.="SUIVI|".$row['nature']."||".$departement."|".$commune."|".$row['annee']."|".
546 substr($row['dossier'],4,5)."|".substr($row['dossier'],9,2)."";
547 $suivi2.="||||||||||";
548 // datereoc date de chantier
549 //|datereat
550 $suivi2.="|".substr($row['date_achevement'],8,2).substr($row['date_achevement'],5,2).substr($row['date_achevement'],0,4); // ok *** au format francais
551 //|nblogat|nbmaisat|nbcollat
552 $suivi2.="|||";
553 //|shonat
554 $suivi2.="|".floor($row['shon']); // ok *** enlever les decimales
555 //|finisat|finaaat|finptzat|finafat|indat|
556 $suivi2.="||||||";
557 // Finchantier 1 si etat=cloturer sinon 0
558 if ($row['etat']=="cloturer"){
559 $suivi2.="1|";
560 }else{
561 $suivi2.="0|";
562 }
563 // Origat 1 par defaut ?????????????????????????????
564 $suivi2.="1";
565 $suivi2.="\n";
566 }// fin doc
567 }
568 if($DEBUG==1){
569 $temp=explode("\n",$suivi2);
570 $temp1=sizeof($temp)-1;
571 for($g=0;$g<$temp1;$g++){
572 $temp2=array();
573 $temp2 = explode("|",$temp[$g]);
574 $v=$g+1;
575 echo "<br><br> DAT : ".$v." ============== <br>";
576 for($k=0;$k<sizeof($temp2);$k++){
577 $t=$k+1;
578 echo $t." : ".$temp2[$k]."<br>";
579 }
580 }
581 }
582 //$res -> free ();
583
584
585 // ==================================================================================
586 // Transfert TRANSFERT
587 // ==================================================================================
588 // element declancheur : Transfert
589 // zone types= Transfert
590 $sql= "select date_achevement, annee, dossier.dossier, demandeur_civilite, dossier.nature,demandeur_categorie,
591 categorie_demandeur.libelle as categorie_libelle,demandeur_nom,demandeur_societe,demandeur_adresse,
592 demandeur_ville,demandeur_cp,demandeur_email,delegataire,parcelle, terrain_numero,
593 terrain_numero_complement,terrain_adresse,terrain_adresse_complement, terrain_ville, terrain_cp,
594 architecte from dossier
595 left join categorie_demandeur on demandeur_categorie= categorie_demandeur.categorie_demandeur";
596 $sql.= " where date_depot>='".substr($_POST["datedebut"],6,4).
597 "-".substr($_POST["datedebut"],3,2)."-".
598 substr($_POST["datedebut"],0,2)."'";
599 $sql.= " AND date_depot<='".substr($_POST["datefin"],6,4).
600 "-".substr($_POST["datefin"],3,2)."-".
601 substr($_POST["datefin"],0,2)."'";
602 $sql.= " AND types= 'Transfert'";
603 echo "<BR><br><font style='background-color:#ffffff;border : 1px solid #000000'>TRANSFERT</font> ".$sql;
604 // date du transfert ?
605 $res = $f->db -> query ($sql);
606 $f->isDatabaseError($res);
607 $transfert="";
608 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
609 $nombreenregistrement++;
610 $cpt_transfert++;
611 // sitadel : mouv|typpermis|equivalence|dep|commune|andepnumpc|indmod
612 // typepermis = dossier.nature
613 // annee = dossier.annee
614 // andepnumpc|indmod = substr dossier.dossier
615 $transfert.="TRANSFERT|".$row['nature']."||".$departement."|".$commune."|".$row['annee']."|".
616 substr($row['dossier'],4,5)."|".substr($row['dossier'],9,2)."|";
617 //ajout aout2010-----IDEM DEPOT codedemo à suivi (---- sauf civtiers|*prenomtier*|nomtier|*numvoietiers*|*typvoietiers*|
618 // libvoietiers|lieudittier|communetier|codpostier|*bptier*|*cedextier*|*paystier*|
619 // *divtertier et telmo----)
620 // codemo|
621 if($row['demandeur_categorie']==9 or $row['demandeur_categorie']=="")
622 $codemo=1;// personne physique
623 else
624 $codemo=2;// personne morale
625 $transfert.=$codemo."|"; // 1 personne physique ; 2 sinon
626 // openfoncier civilite (5/8 ok), nom (80/30-> substr), societe (80/50->substr)
627 // civpart|prenompart|nompart|denopm|rspm|siret|catjur|civrep|prenomrep|nomrep|
628 // suivant codemo = 1 (personne physique) ou 2 (personne morale)
629 // attention : $row['demandeur_civilite']. non standart
630
631 if($codemo==1){
632 // civpart|*prenompart*|nompart||||||
633
634 $transfert.= "||";
635 $transfert.= maj(substr($row['demandeur_nom'],0,30))."|||||||";
636 }else{
637 //denopm|rspm|*siret*|*catjur*|civrep|*prenomrep*|nomrep|
638 $transfert.="|||".maj(substr($row['demandeur_societe'],0,50))."|";
639 $transfert.=maj(substr($row['categorie_libelle'],0,30))."|";
640 $transfert.="||||".
641 maj(substr($row['demandeur_nom'],0,30))."|"; // pas de prenom
642 }
643 // openfoncier : adresse (80/ 26+38 -> substr sur 2 zones) - cp (5/5 OK) - ville (30/36 -> OK)
644 // *numvoiemo*|*typvoiemo*|libvoiemo|lieuditmo(+)|communemo|codposmo|*bpmo*|*cedexmo*|*paysmo*|*divetermo|
645 $transfert.= "|||".maj(substr($row['demandeur_adresse'],0,26))."|".
646 maj(substr($row['demandeur_adresse'],26,38))."|";
647 $transfert.= maj($row['demandeur_ville'])."|".$row['demandeur_cp']."|||||";
648 // sitadel : melmo|
649 $transfert.= $row['demandeur_email']."|";
650 // sitadel: suivi
651 if($row['delegataire']=='Oui'){
652 $transfert.= "1";
653 }else{
654 $transfert.= "0";
655 }
656 //-------------------
657 $transfert.="\n";
658 }// fin while transfert
659 //$res -> free ();
660 if($DEBUG==1){
661 $temp=explode("\n",$transfert);
662 $temp1=sizeof($temp)-1;
663 for($g=0;$g<$temp1;$g++){
664 $temp2=array();
665 $temp2 = explode("|",$temp[$g]);
666 $v=$g+1;
667 echo "<br><br> DAT : ".$v." ============== <br>";
668 for($k=0;$k<sizeof($temp2);$k++){
669 $t=$k+1;
670 echo $t." : ".$temp2[$k]."<br>";
671 }
672 }
673 } // debug
674
675 // ==================================================================================
676 // modificatif MODIFICATIF
677 // ==================================================================================
678 // element declancheur : modificatif
679 // zone types= Modificatif
680 // suivant date-depot et dcision du modificatif
681 $sql= "select annee, dossier.dossier, dossier.nature,
682 dossier.date_decision, avis.sitadel as avis_sitadel, avis.sitadel_motif as avis_sitadel_motif,
683 dossier.terrain_numero,dossier.terrain_adresse,dossier.terrain_cp,dossier.terrain_ville,
684 dossier.parcelle,
685 dossier.terrain_surface,
686 travaux.codelascot as lascot,
687 date_achevement, shon, hauteur, piece_nombre, logement_nombre, batiment_nombre
688 from dossier left join avis on avis.avis= dossier.avis
689 left join travaux on dossier.travaux=travaux.travaux";
690 $sql.= " where (date_depot>='".substr($_POST["datedebut"],6,4).
691 "-".substr($_POST["datedebut"],3,2)."-".
692 substr($_POST["datedebut"],0,2)."'";
693 $sql.= " AND date_depot<='".substr($_POST["datefin"],6,4).
694 "-".substr($_POST["datefin"],3,2)."-".
695 substr($_POST["datefin"],0,2)."'";
696 $sql.= " AND types= 'Modificatif')";
697 $sql.= " or (date_decision>='".substr($_POST["datedebut"],6,4).
698 "-".substr($_POST["datedebut"],3,2)."-".
699 substr($_POST["datedebut"],0,2)."'";
700 $sql.= " AND date_decision<='".substr($_POST["datefin"],6,4).
701 "-".substr($_POST["datefin"],3,2)."-".
702 substr($_POST["datefin"],0,2)."'";
703 $sql.= " AND types= 'Modificatif')";
704 echo "<BR><br><font style='background-color:#ffffff;border : 1px solid #000000'>MODIFICATIF</font>".$sql;
705 // ou dat ???
706 $res = $f->db -> query ($sql);
707 $f->isDatabaseError($res);
708 $modificatif="";
709 // aout 2010 -------------------------------------------------------------------
710 while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
711 $nombreenregistrement++;
712 $cpt_modificatif++;
713 // sitadel : mouv|typpermis|equivalence|dep|commune|andepnumpc|indmod
714 // typepermis = dossier.nature
715 // annee = dossier.annee
716 // andepnumpc|indmod = substr dossier.dossier
717 $modificatif.="MODIFICATIF|".$row['nature']."||".$departement."|".$commune."|".$row['annee']."|".
718 substr($row['dossier'],4,5)."|".substr($row['dossier'],9,2)."|";
719 // sitadel : collectivite|natdec|datredec|motifannul difference avec decision -> *** dateredec a la place de datedec
720 $modificatif.= '1|'; // au nom de la commune
721 // zone supplementaire dans avis
722 // ALTER TABLE `avis` ADD `sitadel_motif` VARCHAR( 1 ) NOT NULL ;
723 // 0 à 8
724 $modificatif.= $row['avis_sitadel']."|";
725 // date au format francais 8 caracteres
726 if ($row['date_decision']!= '0000-00-00' and isset($row['date_decision']))
727 $modificatif.= substr($row['date_decision'],8,2).''.substr($row['date_decision'],5,2)."".substr($row['date_decision'],0,4)."|";
728 else
729 $modificatif.= "|";
730 // Motif d annulation
731 // zone supplementaire dans avis;
732 // ALTER TABLE `avis` ADD `sitadel_motif` VARCHAR( 1 ) NOT NULL ;
733 $modificatif.= $row['avis_sitadel_motif']."";
734 if(isset($row['avis_sitadel']))
735 $avis = $row['avis_sitadel'];
736 else
737 $avis =0;
738 // =============================================================
739 // GROUPE 2 si decision favorable, expresse ou tacite GROUPE 2
740 // =============================================================
741 if($avis==2 or $avis==4 or $avis==5 or $avis==0){// decision positive ou encours
742 // sitadel : |numvoiete|*typvoiete*|libvoiete|lieudite|communete|codposte|*bpte*|*cedexte*|
743 $modificatif.= "|".substr($row['terrain_numero'],0,4)."|"; // typevoie
744 $modificatif.= "|".maj(substr($row['terrain_adresse'],0,26))."|".
745 maj(substr($row['terrain_adresse'],26,38))."|";
746 $modificatif.= maj($row['terrain_ville'])."|";
747 $modificatif.= $row['terrain_cp']."|";
748 $modificatif.= "||";
749 // sitadel : scadastre1|ncadastre1|*scadastre2*|*ncadastre2*|*scadastre3*|*ncadastre3*|
750 $modificatif.= substr($row['parcelle'],0,2)."|";
751 $modificatif.= substr($row['parcelle'],2,4)."|||||";
752 //terrain/libmotif/natrav/annexe/nvmax
753 $modificatif.= floor($row['terrain_surface'])."|";
754 //libmotif
755 $modificatif.= '|';
756 //natrav
757 $nattrav="0000";
758 if($row['lascot']=='2') $nattrav="1000";
759 if($row['lascot']=='3') $nattrav="0100";
760 $modificatif.= $nattrav."|";
761 //annexe
762 $modificatif.= "00000|";
763 //nvmax
764 $modificatif.= "|";
765 // shon avant travaux shionnnant1 a 9 -> non renseigne
766 $modificatif.= "|||||||||";
767 //shondem1 à 9| shonanttr1 à 9| shonprojtr 1 à 9|shoncr1 a 9 |shon2cr1 a 9
768 // table destination
769 $sql1="select destination, shon from destination_shon where dossier = '". $row['dossier']."'";
770 // faire une boucle et remplir
771 //**************************************************************
772 $res1 = $f->db -> query ($sql1);
773 $f->isDatabaseError($res);
774 //
775 $tmpPD = array(); // shon existante demolie
776 for($i=0;$i<=9;$i++)
777 {
778 $tmpPD[$i]='';
779 }
780 //
781 $tmplascot4 = array(); // shon changement de destination
782 for($i=0;$i<=9;$i++)
783 {
784 $tmplascot4[$i]='';
785 }
786 //
787 $tmplascot1 = array(); // shon nouvellement construite
788 for($i=0;$i<=9;$i++)
789 {
790 $tmplascot1[$i]='';
791 }
792 //
793 $tmplascot2 = array(); // shon cree par transformation
794 for($i=0;$i<=9;$i++)
795 {
796 $tmplascot2[$i]='';
797 }
798 while ($row1=& $res1->fetchRow(DB_FETCHMODE_ASSOC)){
799 // shonprojtr1 a 9 / shoncr1 a 9 /
800 if($row['nature']== 'PD') {
801 $tmpPD[$row1['destination']] = $row1['shon']; // shon existante demolie -> a remplir
802 }
803 if($row['lascot']== '4') {
804 $tmplascot4[$row1['destination']] = $row1['shon'];// shon changement de destination -> a remplir
805 }
806 if($row['lascot']== '1'){
807 $tmplascot1[$row1['destination']] = $row1['shon'];// shon nouvellement construite -> a remplir
808 }
809 if($row['lascot']== '2') {
810 $tmplascot2[$row1['destination']] = $row1['shon'];// shon cree par transformation -> a remplir
811 }
812 }
813 // shon existante demolie -> a remplir
814 for($i=1;$i<=9;$i++)
815 {
816 $modificatif.=$tmpPD[$i].'|';
817 }
818 //
819 $modificatif.= "|||||||||";// shon supprimmee par changement de destination -> non renseigne
820 //
821 //$row['lascot']== '4' shon changement de destination
822 for($i=1;$i<=9;$i++)
823 {
824 $modificatif.=$tmplascot4[$i].'|';
825 }
826 //shon nouvellement construite
827 for($i=1;$i<=9;$i++)
828 {
829 $modificatif.=$tmplascot1[$i].'|';
830 }
831 //shon cree par transformation
832 for($i=1;$i<=9;$i++)
833 {
834 $modificatif.=$tmplascot2[$i].'|';
835 }
836 //**************************************************************
837 // cpublic : non renseignee N par defaut
838 // O/N transport/enseignement/sante/social/special/culture
839 $modificatif.= "000000";
840 // nbmaison : nombre de maison
841 $modificatif.= "|".$row['batiment_nombre'];
842 // nblogcoll : nombre de logement collectif
843 $modificatif.= "|".$row['logement_nombre'];
844 // nbtotlog : nombre de logement total
845 $modificatif.= "|".$row['logement_nombre'];
846 // natres : nature des residences
847 // O/N 1=ages, 2=etudiant, 3=tourisme, 4=hotel, 5=social, 6= handicap, 7=autres
848 $modificatif.= "|0000000";
849 // libres= si autre residence (long max 1000 c)
850 $modificatif.= "|";
851 // util : O/N personnel, principale, secondaire, vente, location
852 $modificatif.= "|00000";
853 //chambres
854 $modificatif.= "|";
855 //finis (nb logement locatif sociaux)/finaa(nb logementfinancement aidé)
856 //finptz (nb logement pret taux 0)/finaf (nb logement autrement)/
857 //piec1 à 6 (nb logement 1 a 6pieces )
858 $modificatif.= "||||||||||";
859 }//fin GROUPE 2
860 $modificatif.="\n";
861 }// fin while modificatif
862
863 if($DEBUG==1){
864 $temp=explode("\n",$modificatif);
865 $temp1=sizeof($temp)-1;
866 for($g=0;$g<$temp1;$g++){
867 $temp2=array();
868 $temp2 = explode("|",$temp[$g]);
869 $v=$g+1;
870 echo "<br><br> DAT : ".$v." ============== <br>";
871 for($k=0;$k<sizeof($temp2);$k++){
872 $t=$k+1;
873 echo $t." : ".$temp2[$k]."<br>";
874 }
875 }
876 } // fin debug
877
878 // ***************************************
879 // entete de l enregistrement page 8 et 9
880 // ***************************************
881 // numero
882 //$numero= $db -> nextId('sitadel');
883 $numero=$_POST["numero"];
884 $fichiertransmis = date('ymj').$departement.$commune;
885 $longueurenregistrement= 0 ; // a calculer *** enregistrement le plus long
886 $entete = "SITADEL|".$departement."|".$commune."|".$region."|".$fichiertransmis."|".$numero."|";
887 // calcul enregistrement le plus long
888 $tmpenr="";
889 $tmpenr=$depot.$decision.$suivi1.$suivi2.$transfert.$modificatif;
890 if($flag_utf8_decode==1){
891 $tmpenr=utf8_decode($tmpenr);
892 }else{
893 if($flag_utf8_encode==1){
894 $tmpenr=utf8_encode($tmpenr);
895 }
896 }
897 $nbenr = explode("\n",$tmpenr);
898 $tmp=array();
899 $cpt=0;
900 for($i=0;$i<sizeof($nbenr);$i++){
901 // mb_strlen( variable,encoding) PHP 4 >= 4.0.6, PHP 5
902 // Le paramètre encoding est l'encodage des caractères.
903 // S'il est omis, l'encodage de caractres interne sera utilisé.
904 $tmp[$i] = strlen($nbenr[$i]);
905 //echo strlen($nbenr[$i])." ".$nbenr[$i]."<br>";
906 $cpt++;
907 }
908 $longueurenregistrement=max($tmp);
909 //tri tableau
910 array_multisort($tmp,SORT_DESC);
911 //exact cpt-1+1 (cpt -1( tableau 0 à n ) +1(enregistrement entete) )
912 echo "<BR><br>Nombre Total Enregistrement : ".$cpt." <-> ".$nombreenregistrement."<br><br>";
913 echo "Détail :<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- DEPOT : ".$cpt_depot."<br>";
914 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- DECISION vide suite DEPOT: ".$cpt_decisionsuivantdepot."<br>";
915 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- DECISION : ".$cpt_decision."<br>";
916 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- SUIVI 1 : ".$cpt_suivi1."<br>";
917 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- SUIVI 2 : ".$cpt_suivi2."<br>";
918 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- TRANSFERT : ".$cpt_transfert."<br>";
919 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- MODIFICATIF : ".$cpt_modificatif."<br>";
920 echo "TOTAL : ".($cpt_depot+$cpt_decisionsuivantdepot+$cpt_decision+$cpt_suivi1+$cpt_suivi2+$cpt_transfert+$cpt_modificatif)." + 1 enregistrement(entete)";
921 echo "<br><br>Longueur Enregistrement le plus long : ".max($tmp)." <-> ".$tmp[0];
922
923 // Date de modification
924 $datemodification = date('y').str_pad (DATE('m'), 2, "0", STR_PAD_LEFT).str_pad (DATE('j'), 2, "0", STR_PAD_LEFT);
925
926
927 $entete.= $longueurenregistrement."|".$datemodification."|".$nombreenregistrement."|openFoncier|".$versionapplicatif."\n";
928 $export=$entete.$depot.$decision.$suivi1.$suivi2.$transfert.$modificatif;
929
930 if($flag_utf8_decode==1){
931 $export=utf8_decode($export);
932 }else{
933 if($flag_utf8_encode==1){
934 $export=utf8_encode($export);
935 }
936 }
937 //$str = htmlentities($str, ENT_QUOTES);
938 // ecriture des fichiers en tmp
939 $fichier = "../tmp/SITADEL".substr($_POST["datedebut"],3,2).
940 "".substr($_POST["datedebut"],8,4)."_test";
941 $inf = fopen($fichier,"w");
942 //$export=substr($export,0,strlen($export)-1); // un \n en trop
943 fwrite($inf,$export);
944 fclose($inf);
945 echo "<table class='dossier' width='95%'>";
946 echo "<tr class='dossier'><td>";
947 echo "<br>Fichier ".$fichier." sauvegarde<br><br><br>";
948 $affiche="";
949 if($DEBUG==1)
950 $affiche= str_replace("\n","<br>",$export);
951 // affichage
952 echo "<br /><br />Pour télécharger le fichier, cliquer ici : <a href=\"".$fichier."\" target=\"_blank\">";
953 echo "<img src=\"../img/ico_trace.png\" alt=\"Télécharger le fichier CNEN\" title=\"Télécharger le fichier CNEN\" />";
954 echo "</a> avec le bouton droit et enregistrer la cible du lien sous. <br /><br />";
955 echo $affiche;
956 //echo"<img src='../img/retour.png' align='top' border='0'>";
957 // echo "</a></center>";
958 echo "</td></tr></table>";
959 }else
960 echo "remplissez les 2 dates";
961 }//validation
962 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26