2016-08-03 14:41:42 +02:00

476 lines
18 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class Metier_Partenaires_MCadastre
{
/**
* Siren
* @var string
*/
protected $siren = null;
/**
* Database
* @var Metier_Util_Db
*/
protected $iDb;
/**
* Droits des locaux
* @var array
*/
private static $codeDroit = array(
'A' => 'Locataire-Attributaire', // (associé avec P)
'B' => 'Bailleur à construction', // (associé avec R)
'C' => 'Fiduciaire',
'D' => 'Domanier', // (associé avec F)
'E' => 'Emphytéote', // (associé avec P)
'F' => 'Foncier', // (associé avec D ou T)
'G' => 'Gérant, mandataire, gestionnaire',
'H' => 'Associé dans une société en transparence fiscale', // (associé avec P)
'J' => 'Jeune agriculteur',
'K' => 'Antichrésiste', // (associé avec P)
'L' => 'Fonctionnaire logé',
'M' => 'Occupant d\'une parcelle appartenant au département de Mayotte ou à l\'Etat', // (associé avec P)
'N' => 'Nu-propriétaire', // (associé avec U)
'O' => 'Autorisation d\'occupation temporaire (70 ans)',
'P' => 'Propriétaire',
'Q' => 'Gestionnaire taxe sur les bureaux (Ile-de-France)',
'R' => 'Preneur à construction', // (associé avec B)
'S' => 'Syndic de copropriété',
'T' => 'Tenuyer', // (associé avec F)
'U' => 'Usufruitier', // (associé avec N)
'V' => 'Bailleur d\'un bail à réhabilitation', // (associé avec W)
'W' => 'Preneur d\'un bail à réhabilitation', // (associé avec V)
'X' => 'La Poste Occupant et propriétaire',
'Y' => 'La Poste Occupant et non propriétaire',
);
/**
* Nature des locaux
* @var array
*/
private static $natureLocaux = array(
'AP' => 'Appartement',
'AT' => 'Antenne téléphone',
'AU' => 'Autoroute',
'CA' => 'Commerce sans boutique',
'CB' => 'Local divers',
'CD' => 'Dépendance commerciale',
'CH' => 'Chantier',
'CM' => 'Commerce avec boutique',
'DC' => 'Dépendance lieux communs',
'DE' => 'Dépendance bâtie isolée',
'LC' => 'Local commun',
'MA' => 'Maison',
'ME' => 'Maison exceptionnelle',
'MP' => 'Maison partagée par une limite territoriale',
'PP' => 'ND',
'SM' => 'Sol de maison',
'U' => 'Etablissement industriel',
'U1' => 'Gare',
'U2' => 'Gare - Triage',
'U3' => 'Gare - Atelier matériel',
'U4' => 'Gare - Atelier magasin',
'U5' => 'Gare - Dépôt Titulaire',
'U6' => 'Gare - Dépôt Réel',
'U7' => 'Gare - Matériel transport',
'U8' => 'Gare - Entretien matériel roulant',
'U9' => 'Gare - Station usine',
'UE' => 'Transformateur électrique',
'UG' => 'Appareil à gaz',
'UN' => 'Usine nucléaire',
'US' => 'Etablissement industriel',
);
/**
* Code Affectation des PEV (Partie d'EValuation)
* @var array
*/
private static $PEV = array(
'A' => 'Locaux commerciaux/Biens divers passibles de la TH', // Nouveau en 2014
'B' => 'Bâtiment industriel', // lié à CCOEVA = A OU E
'C' => 'Commerce',
'E' => 'Locaux commerciaux/Biens divers non passibles de TH et TP', // Nouveau en 2014
'H' => 'Habitation',
'K' => 'Locaux administratifs non passibles de la TH',
'L' => 'Hôtel',
'P' => 'Professionnel',
'S' => 'Biens divers passibles de la TH',
'T' => 'Terrain industriel', // lié à CCOEVA = A OU E
);
/**
* Code Groupes Personnes Morales
* @var array
*/
private static $grpPersonnesMorales = array(
// Si suivi de la lettre "A" : personnes soumises à la CAAA (caisses d'assurance accidents agricoles) en Alsace et en Moselle
0 => 'Personne morale', // non remarquable
1 => 'Etat',
2 => 'Région',
3 => 'Département',
4 => 'Commune',
5 => 'Office HLM',
6 => 'Personne morale représentant des sociétés',
7 => 'Copropriétaire',
8 => 'Associé',
9 => 'Etablissement public ou organismes assimilés',
);
/**
* Code Formes Juridiques spécifiques du Cadastre
* @var array
*/
private static $FjCad = array(
'F001' => 'Les copropriétaires',
'F002' => 'Les associés de la SCI (en transparence fiscale)',
'F003' => 'Professionnels très pauvres du foncier',
);
/**
* Nature des parcelles (cultures)
* @var array
*/
private static $natureParcelles = array(
'AB' => 'Terrains à batir',
'AG' => 'Terrains d\'agrément',
'B' => 'Bois',
'BF' => 'Futaies feuillues',
'BM' => 'Futaies mixtes',
'BO' => 'Oseraies',
'BP' => 'Peupleraies',
'BR' => 'Futaies résineuses',
'BS' => 'Taillies sous futaies',
'BT' => 'Taillies simples',
'CA' => 'Carrières',
'CH' => 'Chemins de fer, Canaux de Navigation',
'E' => 'Eaux',
'J' => 'Jardins',
'L' => 'Landes',
'LB' => 'Landes Boisées',
'P' => 'Prés',
'PA' => 'Pâtures ou Pâturages',
'PC' => 'Pacages ou Pâtis',
'PE' => 'Prés d\'embouche',
'PH' => 'Herbages',
'PP' => 'Prés, Pâtures ou Herbages plantes',
'S' => 'Sols',
'T' => 'Terre',
'TP' => 'Terres plantées',
'VE' => 'Vergers',
'VI' => 'Vignes',
);
/**
* Cadastre
* @param string $siren
* @param Metier_Util_Db $db
*/
public function __construct($siren = null, $db = null)
{
$this->siren = $siren;
if ( $db === null ) {
$this->iDb = new Metier_Util_Db();
} else {
$this->iDb = $db;
}
}
/**
* Type de personne morale au cadastre
* @param string $ccogrm
* @return string
*/
public function getTypeRM($ccogrm)
{
$ccogrm = trim($ccogrm);
if (array_key_exists($ccogrm, self::$grpPersonnesMorales)) {
$lib = self::$grpPersonnesMorales[$ccogrm];
} elseif (array_key_exists(intval(substr($ccogrm,0,1)), self::$grpPersonnesMorales)) {
$lib = self::$grpPersonnesMorales[intval(substr($ccogrm,0,1))];
if (substr($ccogrm,1,1) == 'A') {
$lib.= " soumis à CAAA (Caisses d'Assurance Accidents Agricoles) en Alsace et en Moselle";
}
} else {
$lib = '';
}
return $lib;
}
/**
* Nature des locaux ou parcelles
* @param string $code
* @param string $type
* @return string
*/
public function getNatureLabel($code, $type = 'local')
{
if ($type == 'local') {
if (array_key_exists($code, self::$PEV)) {
return self::$PEV[$code];
}
} elseif ($type == 'parcelle') {
if (array_key_exists($code, self::$natureParcelles)) {
return self::$natureParcelles[$code];
}
}
return '';
}
/**
* Locaux : Propriétés baties
* @param string $siren
* @return array
*/
public function getLocaux($siren = null)
{
if ($siren === null) {
$siren = $this->siren;
}
$results = $this->iDb->select(
'sdv1.cad_perloc l, sdv1.cad_permor e',
'e.INTCIF, e.DNUPER, e.CCOGRM, e.DDENPM, e.DSIPMO, e.DFORME, e.DSIREN, e.DLIGN3, e.DLIGN4, e.DLIGN5, e.DLIGN6, e.CCODEP, e.CCOCOM AS companyCCOCOM,
l.CCODRO, l.CCOCOM, l.CCOPRF, l.CCOSEC, l.DNUPLA, l.DNUBAT, l.DESC, l.DNIV, l.DPOR, l.CCONLC, l.CCOAFF0, l.DSUPOD0, l.CCOAFF1, l.DSUPOD1, l.CCOAFF2, l.DSUPOD2, l.CCOAFF3, l.DSUPOD3, l.CCOAFF4, l.DSUPOD4, l.CCOAFF5, l.DSUPOD5, l.CCOAFF6, l.DSUPOD6, l.CCOAFF7, l.DSUPOD7, l.CCOAFF8, l.DSUPOD8, l.CCOAFF9, l.DSUPOD9, l.CCODEP, l.DLICOM, l.CCORIV, l.CNAVOI, l.DLIVOI, l.DNUVOI, l.DLTNUV',
"e.DSIREN='$siren' AND e.INTCIF=l.INTCIF AND e.DNUPER=l.DNUPER", false, MYSQL_ASSOC);
$locaux = array();
if (count($results) > 0) {
foreach ($results as $i => $loc) {
$format = array(
'idCentre' => $loc['INTCIF'],
'idPmMajic' => $loc['DNUPER'],
'pmGroupe' => trim($loc['CCOGRM']),
'pmGroupeLib' => $this->getTypeRM(trim($loc['CCOGRM'])),
'pmNom' => trim($loc['DDENPM']),
'pmSigle' => trim($loc['DSIPMO']),
'pmFJ' => $loc['DFORME'],
'siren' => trim($loc['DSIREN']),
'pmAdrL3' => trim($loc['DLIGN3']),
'pmAdrL4' => trim($loc['DLIGN4']),
'pmAdrL5' => trim($loc['DLIGN5']),
'pmAdrL6' => trim($loc['DLIGN6']),
'pmAdrDep' => trim($loc['CCODEP']),
'pmAdrCom' => trim($loc['companyCCOCOM']),
'localDroit' => trim($loc['CCODRO']),
'localDroitLib' => self::$codeDroit[trim($loc['CCODRO'])],
'localDep' => trim($loc['CCODEP']),
'localCom' => trim($loc['CCOCOM']),
'localComLib' => trim($loc['DLICOM']),
'localComAbs' => trim($loc['CCOPRF']),
'localRivoli' => trim($loc['CCORIV']),
'localNumVoie' => trim($loc['DNUVOI']),
'localIndVoie' => trim($loc['DLTNUV']),
'localTypVoie' => trim($loc['CNAVOI']),
'localLibVoie' => trim($loc['DLIVOI']),
'localSection' => trim($loc['CCOSEC']),
'localNumPlan' => trim($loc['DNUPLA']),
'localNumBat' => trim($loc['DNUBAT']),
'localEntEsc' => trim($loc['DESC']),
'localNiveau' => trim($loc['DNIV']),
'localEntEsc' => trim($loc['CCONLC']),
'localPEV' => array(),
);
// Calcul de surface
$surface = 0;
for($j = 0; $j < 10; $j++) {
$pevCode = trim($loc['CCOAFF'.$j]);
$pevSurf = intval(trim($loc['DSUPOD'.$j]));
if ($pevCode != '' && $pevSurf > 0) {
$format['localPEV'][$j] = array(
'pevCode' => $pevCode,
'pevType' => self::$PEV[$pevCode],
'pevSurface' => $pevSurf,
);
$surface+= $pevSurf;
}
}
$format['localSurface'] = $surface;
$locaux[] = $format;
}
}
return $locaux;
}
/**
* Parcelles : Propriétés non baties
* @param string $siren
* @return array
*/
public function getParcelles($siren = null)
{
if ($siren === null) {
$siren = $this->siren;
};
$results = $this->iDb->select(
'sdv1.cad_perpar p, sdv1.cad_permor e',
'e.INTCIF, e.DNUPER, e.CCOGRM, e.DDENPM, e.DSIPMO, e.DFORME, e.DSIREN, e.DLIGN3, e.DLIGN4, e.DLIGN5, e.DLIGN6, e.CCODEP, e.CCOCOM AS companyCCOCOM,
p.CCODRO, p.CCOCOM, p.CCOPRF, p.CCOSEC, p.DNUPLA, p.DCNPAR, p.DSGRPF0, p.DCNSUF0, p.DSGRPF1, p.DCNSUF1, p.DSGRPF2, p.DCNSUF2, p.DSGRPF3, p.DCNSUF3, p.DSGRPF4, p.DCNSUF4, p.DSGRPF5, p.DCNSUF5, p.DSGRPF6, p.DCNSUF6, p.DSGRPF7, p.DCNSUF7, p.DSGRPF8, p.DCNSUF8, p.DSGRPF9, p.DCNSUF9, p.CCODEP, p.DLICOM, p.CCORIV, p.CNAVOI, p.DLIVOI, p.DNUVOI, p.DLTNUV',
"e.DSIREN='$siren' AND e.INTCIF=p.INTCIF AND e.DNUPER=p.DNUPER", false, MYSQL_ASSOC);
$parcelles = array();
if (count($results) > 0) {
foreach ($results as $i => $loc) {
$format = array(
'idCentre' => $loc['INTCIF'],
'idPmMajic' => $loc['DNUPER'],
'pmGroupe' => trim($loc['CCOGRM']),
'pmGroupeLib' => $this->getTypeRM(trim($loc['CCOGRM'])),
'pmNom' => trim($loc['DDENPM']),
'pmSigle' => trim($loc['DSIPMO']),
'pmFJ' => $loc['DFORME'],
'siren' => trim($loc['DSIREN']),
'pmAdrL3' => trim($loc['DLIGN3']),
'pmAdrL4' => trim($loc['DLIGN4']),
'pmAdrL5' => trim($loc['DLIGN5']),
'pmAdrL6' => trim($loc['DLIGN6']),
'pmAdrDep' => trim($loc['CCODEP']),
'pmAdrCom' => trim($loc['companyCCOCOM']),
'parcelDroit' => trim($loc['CCODRO']),
'parcelDroitLib' => self::$codeDroit[trim($loc['CCODRO'])],
'parcelDep' => trim($loc['CCODEP']),
'parcelCom' => trim($loc['CCOCOM']),
'parcelComLib' => trim($loc['DLICOM']),
'parcelComAbs' => trim($loc['CCOPRF']),
'parcelRivoli' => trim($loc['CCORIV']),
'parcelNumVoie' => trim($loc['DNUVOI']),
'parcelIndVoie' => trim($loc['DLTNUV']),
'parcelTypVoie' => trim($loc['CNAVOI']),
'parcelLibVoie' => trim($loc['DLIVOI']),
'parcelSection' => trim($loc['CCOSEC']),
'parcelNumPlan' => trim($loc['DNUPLA']),
'parcelSurface' => trim($loc['DCNPAR'])*1,
'parcelTer' => array(),
);
// Calcul de surface
$surface = 0;
for($j = 0; $j < 10; $j++) {
$pevCode = trim($loc['DSGRPF'.$j]);
$pevSurf = trim($loc['DCNSUF'.$j])*1;
if ($pevCode != '' && $pevSurf > 0) {
$format['parcelTer'][$j] = array(
'terCode' => $pevCode,
'terType' => self::$natureParcelles[$pevCode],
'terSurface' => $pevSurf,
);
$surface+= $pevSurf;
}
}
$format['parcelSurfaceCalc'] = $surface;
$parcelles[] = $format;
}
}
return $parcelles;
}
/**
* List des éléments du patrimoine
* @return array
*/
public function patrimoine()
{
$locauxSql = "SELECT 'local' AS type, " .
"l.CCODRO AS role, " .
"l.DNUVOI AS adresseNum, " .
"l.DLTNUV AS adresseInd, " .
"l.CNAVOI AS adresseType, " .
"l.DLIVOI AS adresseLib, " .
"l.CCODEP AS departement, " .
"l.CCOCOM AS communeCode, " .
"l.DLICOM AS communeLib, " .
"l.CCOSEC AS section, " .
"l.DNUPLA AS planNum, " .
"l.CCORIV AS fantoir, " .
"l.DNUBAT AS batiment, " .
"l.DESC AS ent, " .
"l.DNIV AS niveau, " .
"(l.DSUPOD0 + l.DSUPOD1 + l.DSUPOD2 + l.DSUPOD3 + l.DSUPOD4 + l.DSUPOD5 + l.DSUPOD7 + l.DSUPOD8 + l.DSUPOD9) AS surfaceTotal, " .
"l.CCOAFF0 AS nature0, " .
"l.DSUPOD0 AS surface0, " .
"l.CCOAFF1 AS nature1, " .
"l.DSUPOD1 AS surface1, " .
"l.CCOAFF2 AS nature2, " .
"l.DSUPOD2 AS surface2, " .
"l.CCOAFF3 AS nature3, " .
"l.DSUPOD3 AS surface3, " .
"l.CCOAFF4 AS nature4, " .
"l.DSUPOD4 AS surface4, " .
"l.CCOAFF5 AS nature5, " .
"l.DSUPOD5 AS surface5, " .
"l.CCOAFF6 AS nature6, " .
"l.DSUPOD6 AS surface6, " .
"l.CCOAFF7 AS nature7, " .
"l.DSUPOD7 AS surface7, " .
"l.CCOAFF8 AS nature8, " .
"l.DSUPOD8 AS surface8, " .
"l.CCOAFF9 AS nature9, " .
"l.DSUPOD9 AS surface9, " .
"l.dateInsert " .
"FROM sdv1.cad_perloc l, sdv1.cad_permor e " .
"WHERE e.DSIREN='$this->siren' AND e.INTCIF=l.INTCIF AND e.DNUPER=l.DNUPER";
$parcellesSql = "SELECT 'parcelle' AS type, " .
"p.CCODRO AS role, " .
"p.DNUVOI AS adresseNum, " .
"p.DLTNUV AS adresseInd, " .
"p.CNAVOI AS adresseType, " .
"p.DLIVOI AS adresseLib ," .
"p.CCODEP AS departement, " .
"p.CCOCOM AS communeCode, " .
"p.DLICOM AS communeLib, " .
"p.CCOSEC AS section, " .
"p.DNUPLA AS planNum, " .
"p.CCORIV AS fantoir, " .
"'' AS batiment, " .
"'' AS ent, " .
"'' AS niveau, " .
"p.DCNPAR AS surfaceTotal, " .
"p.DSGRPF0 AS nature0, " .
"p.DCNSUF0 AS surface0, " .
"p.DSGRPF1 AS nature1, " .
"p.DCNSUF1 AS surface1, " .
"p.DSGRPF2 AS nature2, " .
"p.DCNSUF2 AS surface2, " .
"p.DSGRPF3 AS nature3, " .
"p.DCNSUF3 AS surface3, " .
"p.DSGRPF4 AS nature4, " .
"p.DCNSUF4 AS surface4, " .
"p.DSGRPF5 AS nature5, " .
"p.DCNSUF5 AS surface5, " .
"p.DSGRPF6 AS nature6, " .
"p.DCNSUF6 AS surface6, " .
"p.DSGRPF7 AS nature7, " .
"p.DCNSUF7 AS surface7, " .
"p.DSGRPF8 AS nature8, " .
"p.DCNSUF8 AS surface8, " .
"p.DSGRPF9 AS nature9, " .
"p.DCNSUF9 AS surface9, " .
"p.dateInsert " .
"FROM sdv1.cad_perpar p, sdv1.cad_permor e " .
"WHERE e.DSIREN='$this->siren' AND e.INTCIF=p.INTCIF AND e.DNUPER=p.DNUPER";
$sql = "SELECT * FROM ( ($locauxSql) UNION ALL ($parcellesSql) ) results";
$db = Zend_Db_Table::getDefaultAdapter();
//$results = $this->iDb->query($sql, true);
$results = $db->fetchAll($sql, null, Zend_Db::FETCH_ASSOC);
$list = array();
if (count($results) > 0) {
foreach ($results as $result) {
// Libellé role
$result['roleLib'] = self::$codeDroit[trim($result['role'])];
$list[] = $result;
}
}
return $list;
}
}