authenticate(); $this->permission('identite'); //Initialisation if (empty($id)) { $id = 0; } $forceVerif = false; $tabRet = array(); $len = strlen($siret); $siren = substr($siret,0,9); if ($len == 14) { $nic = substr($siret,9,5)*1; } elseif ($len == 9) { $nic = 0; } if ($siren*1==0 && $id==0) { $this->sendError('1010'); } elseif ($len!=14 && $len!=9) { $this->sendError('1020'); } $db = new WDB(); $iInsee = new MInsee($db); $entrep = $iInsee->getIdentiteEntreprise($siren, $nic, $id, $forceVerif); if (empty($entrep) || empty($entrep['id']) ) { $this->sendError('1020'); } $identite = new Identite(); $identite->id = $entrep['id']; $identite->Siret = $entrep['Siret']; $identite->SiretSiege = $entrep['SiretSiege']; $identite->Siege = $entrep['Siege']; $identite->AncienSiege = $entrep['AncienSiege']; $identite->AncienSiegeDateFin = $entrep['AncienSiegeDateFin']; $identite->TribunalCode = prepareString($entrep['Tribunal']); $identite->TribunalLib = prepareString($entrep['TribunalLib']); $identite->NumRC = $entrep['numRC']; $identite->Actif = $entrep['Actif']; $identite->ActifEco = $entrep['ActifEco']; $identite->ActifEcoDate = $entrep['ActifEcoDate']; $identite->ActifEcoType = $entrep['ActifEcoType']; $identite->EntActiveRCS = $entrep['EntActiveRCS']; $identite->AutreId = $entrep['AutreId']; $identite->Source = $entrep['Source']; $identite->SourceId = $entrep['SourceId']; $identite->Isin = $entrep['Isin']; $identite->Nom = $entrep['NOMEN_LONG']; if (empty($identite->Nom)) { $identite->Nom = prepareString(strtr($entrep['Nom'],'/*',' ')); } $identite->Nom2 = prepareString($entrep['Nom2']); $identite->NomLong = prepareString($entrep['nomLong']); $identite->NomCommercial = prepareString($entrep['NomCommercial']); $identite->Siret = $entrep['Siret']; $identite->Sigle = prepareString($entrep['Sigle']); $identite->SigleLong = prepareString($entrep['sigleLong']); $identite->Enseigne = prepareString($entrep['Enseigne']); $identite->EnseigneLong = prepareString($entrep['enseigneLong']); $identite->Adresse = prepareString($entrep['Adresse']); $identite->Adresse2 = prepareString($entrep['Adresse2']); $identite->AdresseNum = prepareString($entrep['AdresseNum']); $identite->AdresseBtq = prepareString($entrep['AdresseBtq']); $identite->AdresseVoie = prepareString($entrep['AdresseVoie']); $identite->AdresseRue = prepareString($entrep['AdresseRue']); $identite->AdresseDistSP = $entrep['AdresseDistSP']; $identite->CP = $entrep['CP']; $identite->Ville = prepareString($entrep['Ville']); $identite->Pays = prepareString($entrep['Pays']); $identite->PaysIso2 = $entrep['PaysIso2']; $identite->AdresseDom = $entrep['AdresseDom']; $tabAdresseDomEnt = array(); if (isset($entrep['AdresseDomEnt']) && count($entrep['AdresseDomEnt'])>0){ foreach ($entrep['AdresseDomEnt'] as $element){ $adresseDomEnt = new AdresseDomEnt(); $adresseDomEnt->siren = $element['siren']; $adresseDomEnt->nom = $element['nom']; $tabAdresseDomEnt[] = $adresseDomEnt; } } $identite->AdresseDomEnt = $tabAdresseDomEnt; $identite->AdresseDomNb = $entrep['AdresseDomNb']; // --- Indicateur Adresse RNVP try { $rnvpM = new Application_Model_VillesRnvpSources(); $sql = $rnvpM->select(true)->columns(array('dateRetourRnvp','codeRetour')) ->where('source=?', $entrep['Source'])->where('source_id=?', $entrep['SourceId']); $rnvpResult = $rnvpM->fetchRow($sql); if ($rnvpResult !== null) { $identite->AdresseRnvpDate = $rnvpResult->dateRetourRnvp; $identite->AdresseRnvpCode = $rnvpResult->codeRetour; } } catch (Zend_Db_Exception $e) {} $identite->Civilite = $entrep['Civilite']; $identite->NbEtab = $entrep['NbEtab']; $identite->Tel = prepareString($entrep['Tel']); $identite->Fax = prepareString($entrep['Fax']); $identite->Web = prepareString($entrep['Web']); $identite->Mail = prepareString($entrep['Mail']); $identite->GeoLat = $entrep['GeoLat']; $identite->GeoLon = $entrep['GeoLon']; $identite->GeoPrecis = $entrep['GeoPrecis']; $geoInfos = new GeoInfos(); $geoInfos->CUCS = $entrep['GeoInfos']['CUCS']; $geoInfos->NCUCS = $entrep['GeoInfos']['NCUCS']; $geoInfos->ZRU = $entrep['GeoInfos']['ZRU']; $geoInfos->NZRU = $entrep['GeoInfos']['NZRU']; $geoInfos->ZFU = $entrep['GeoInfos']['ZFU']; $geoInfos->NZFU = $entrep['GeoInfos']['NZFU']; $geoInfos->ZUS = $entrep['GeoInfos']['ZUS']; $geoInfos->NZUS = $entrep['GeoInfos']['NZUS']; $geoInfos->AFR = $entrep['GeoInfos']['AFR']; $geoInfos->NAFR = $entrep['GeoInfos']['NAFR']; $geoInfos->ZRR = $entrep['GeoInfos']['ZRR']; $geoInfos->NZRR = $entrep['GeoInfos']['NZRR']; $identite->GeoInfos = $geoInfos; $identite->TvaNumero = $entrep['TvaNumero']; $identite->TvaAttribue = $entrep['TvaAttribue']; $identite->FJ = $entrep['FJ']; $identite->FJ_Lib = $entrep['FJ_lib']; $identite->FJ2 = $entrep['FJ2']; $identite->FJ2_Lib = $entrep['FJ2_Lib']; $identite->Siren = $entrep['Siren']; $identite->Nic = $entrep['Nic']; $identite->NafEnt = $entrep['NafEnt']; $identite->NafEntLib = $entrep['NafEntLib']; $identite->NafEtab = $entrep['NafEtab']; $identite->NafEtabLib = $entrep['NafEtabLib']; $identite->NaceEtab = $entrep['NaceEtab']; $identite->NaceEnt = $entrep['NaceEnt']; $identite->Nafa = $entrep['APRM']; $identite->NafaLib = prepareString($entrep['APRM_Lib']); $identite->NumRM = $entrep['NumRM']; $identite->Activite = $entrep['Activite']; $identite->Capital = $entrep['Capital']; $identite->CapitalDev = $entrep['CapitalDev']; $identite->CapitalLib = $entrep['CapitalLib']; $identite->CapitalType = prepareString($entrep['CapitalType']); $classWdate = new WDate(); $identite->DateCreaEt = $classWdate->dateT('Ymd','Y-m-d',$entrep['DateCreaEt']); $identite->DateCreaEn = $classWdate->dateT('Ymd','Y-m-d',$entrep['DateCreaEn']); $identite->DateClotEt = $entrep['DateClotEt']; //@todo : date $identite->DateImmat = $entrep['dateImmat']; $identite->DateRadiation = $entrep['dateRad']; $identite->EffEnTr = $entrep['EffEnTr']; $identite->EffEnTrLib = $entrep['EffEnTrLib']; $identite->Effectif = $entrep['Effectif']; $identite->EffEtTr = $entrep['EffEtTr']; $identite->EffEtTrLib = $entrep['EffEtTrLib']; $identite->EffectifEtab = $entrep['EffectifEtab']; $identite->Dept = $entrep['Dept']; $identite->codeCommune = prepareString($entrep['codeCommune']); $identite->AnneeEffEn = $entrep['AnneeEffEn']; $identite->AnneeEffEt = $entrep['AnneeEffEt']; $identite->AnneeTCA = $entrep['AnneeTCA']; $identite->TrancheCA = $entrep['TrancheCA']; $identite->TrancheCALib = $entrep['TrancheCALib']; $identite->TrancheCAType = $entrep['TrancheCAType']; $identite->dir1Code = $entrep['dir1Code']; $identite->dir1Titre = prepareString($entrep['dir1Titre']); $identite->dir1NomPrenom = prepareString($entrep['dir1NomPrenom']); $identite->dir1DateFct = prepareString($entrep['dir1DateFct']); //@todo : date $identite->dir1DateNaiss = $entrep['dir1DateNaiss']; //@todo : date $identite->dir1LieuNaiss = prepareString($entrep['dir1LieuNaiss']); $identite->dir2Code = $entrep['dir2Code']; $identite->dir2Titre = prepareString($entrep['dir2Titre']); $identite->dir2NomPrenom = prepareString($entrep['dir2NomPrenom']); $identite->dir2DateFct = $entrep['dir2DateFct']; //@todo : date $identite->dir2DateNaiss = prepareString($entrep['dir2DateNaiss']); //@todo : date $identite->dir2LieuNaiss = prepareString($entrep['dir2LieuNaiss']); $identite->Rivoli = $entrep['Rivoli']; $identite->InfosIris = new stdClass(); $identite->InfosIris->codIris = $entrep['InfosIris']['codIris']; $identite->InfosIris->codComIris = $entrep['InfosIris']['codComIris']; $identite->InfosIris->libIris = prepareString($entrep['InfosIris']['libIris']); $identite->InfosIris->typIris = prepareString($entrep['InfosIris']['typIris']); $identite->InfosIris->evoIris = $entrep['InfosIris']['evoIris']; $identite->InfosIris->trIris = $entrep['InfosIris']['trIris']; $identite->InfosIris->grdQuartier = $entrep['InfosIris']['grdQuartier']; $identite->NatureActivite = $entrep['NatureActivite']; // Nature de l'activité $identite->OrigineCreation = $entrep['OrigineCreation']; // Origine de la création $identite->TypeExploitation = $entrep['TypeExploitation']; $identite->Auxiliaire = $entrep['Auxiliaire']; // 1=Auxiliaire / 0=Non auxiliaire $identite->Saisonnalite = $entrep['Saisonnalite']; // P=Activité permanente / S=Activité saisonnière $identite->SurfaceMagasin = $entrep['ACTISURF']*1; // 0=N/D, 1=inf. à 300m2,2=300 à 400m2, 3=400 à 2500m2, 4=sup. à 2500m2 $identite->SituationJuridique = $entrep['SituationJuridique']; $identite->Bilan = new stdClass(); $identite->Bilan->Millesime = $entrep['bilanAnnee']; $identite->Bilan->Cloture = $entrep['bilanDate']; //@todo : date $identite->Bilan->Duree = $entrep['bilanMois']; $identite->Bilan->Devise = $entrep['bilanDevise']; $identite->Bilan->Capital = $entrep['bilanDA']; $identite->Bilan->CA = $entrep['bilanFL']; $identite->Bilan->CAestime = $entrep['bilanFLestime']; $identite->Bilan->Resultat = prepareString($entrep['bilanHN']); $identite->Bilan->Effectif = $entrep['bilanYP']; $iBourse = new MBourse($siren, $db); $bourse = $iBourse->getInfosBourse($siren); if (count($bourse) > 0 ) { $identite->Bourse->placeCotation = $bourse['placeCotation']; $identite->Bourse->nombreTitres = $bourse['nombreTitres']; $identite->Bourse->capitalisation = $bourse['close'] * $bourse['nombreTitres']; $identite->Bourse->derCoursDate = $bourse['date']; //@todo : date $identite->Bourse->derCoursCloture = $bourse['close']; //@todo : date } $tabAutreSiren = array(); if (isset($entrep['AutreSiren'])) { $autreSiren = new AutreSiren(); $autreSiren->siren = $entrep['AutreSiren']['listeSiren']['siren']; $autreSiren->type = $entrep['AutreSiren']['listeSiren']['type']; $tabAutreSiren[] = $autreSiren; } $identite->AutreSiren = $tabAutreSiren; $tabAutreSiret = array(); if (count($entrep['AutreSiret'])) { foreach($entrep['AutreSiret'] as $type => $item) { $autreSiret = new AutreSiret(); $autreSiret->type = $type; $autreSiret->siren = $item['siren']; $autreSiret->nic = $item['nic']; $autreSiret->apeEtab = $item['apeEtab']; $autreSiret->codeEve = $item['codeEve']; $autreSiret->dateEve = $item['dateEve']; $autreSiret->adrL1 = $item['adrL1']; $autreSiret->adrL2 = $item['adrL2']; $autreSiret->adrL3 = $item['adrL3']; $autreSiret->adrL4 = $item['adrL4']; $autreSiret->adrL5 = $item['adrL5']; $autreSiret->adrL6 = $item['adrL6']; $autreSiret->adrL7 = $item['adrL7']; $autreSiret->depCom = $item['depCom']; $autreSiret->rivoli = $item['rivoli']; $autreSiret->siege = $item['siege']; $autreSiret->destinat = $item['destinat']; $autreSiret->typEtab = $item['typeEtab']; $autreSiret->origine = $item['origine']; $tabAutreSiret[] = $autreSiret; } } $identite->AutreSiret = $tabAutreSiret; $identite->DateMajINSEE = $entrep['DateMajINSEE']; //@todo : date $identite->DateMajRCS = $entrep['DateMajRCS']; //@todo : date $identite->DateMajBILAN = $entrep['bilanDateMaj']; //@todo : date $identite->DateMajANN = $entrep['dateMajANN']; //@todo : date $identite->DateMajID = $entrep['dateMajIdentite']; //@todo : date // --- Ancien NAF if (preg_match('/NAF4/i', $this->User->pref)) { $entrep2 = $iInsee->getNaf4($siren, $nic, $id); if ( $entrep2 !== false ) { $identite->Naf4Ent = $entrep2['apen4']; $identite->Naf4Etab = $entrep2['apet4']; $identite->Naf4EntLib = prepareString($entrep2['apen4_lib']); $identite->Naf4EtabLib = prepareString($entrep2['apet4_lib']); } } // --- Détermination du groupe - Tête de groupe if (intval($siren) > 100) { $lienM = new SdMetier_Liens_Base($siren, 'siren'); $grpHeadId = $lienM->getHead(null, 50); $grpFiche = $lienM->getIdentity(); if ($grpFiche->id != $grpHeadId) { $grpHeadFiche = $lienM->getIdentity($grpHeadId); $identite->GroupeId = str_pad($grpHeadFiche->id, 20, 0, STR_PAD_LEFT); // Ajouter source $identite->GroupeName = $grpHeadFiche->RS; // --- Recherche code Isin $nbIdNum = 3; for ($i=0;$i<$nbIdNum;$i++) { if( !empty($grpHeadFiche->{'idLoc'.$i.'Num'}) && $grpHeadFiche->{'idLoc'.$i.'Type'} == 63 ) { $identite->GroupeIsin = $grpHeadFiche->{'idLoc'.$i.'Num'}; break; } } $identite->GroupeCountryCode = $grpHeadFiche->adresse_pays; if (!empty($grpHeadFiche->adresse_pays)) { try { $countryM = new Application_Model_JoTabPays(); $sql = $countryM->select()->from($countryM, array('codPays3', 'libPays')); $result = $countryM->fetchAll($sql); } catch (Zend_Db_Adapter_Exception $e) {} $tabPays = array(); if ( $result->count()>0 ) { foreach ( $result as $item ) { $tabPays[$item->codPays3] = $item->libPays; } } $libPays = ''; if ($grpHeadFiche->adresse_pays!='') { $libPays = array_key_exists($grpHeadFiche->adresse_pays, $tabPays) ? $tabPays[$grpHeadFiche->adresse_pays] : $grpHeadFiche->adresse_pays; } else { $libPays = $tabPays['FRA']; } $identite->GroupeCountryLabel = $libPays; } } } $this->wsLog('identite', $siret, $id); return $identite; } /** * Avis RNCS * @param string $siren * @return AvisRncs */ public function getAvisRncs($siren) { $this->authenticate(); $this->permission('avisrncs'); $len = strlen($siren); if ( $len != 9 ) { $this->sendError('1020'); } $output = new AvisRncs(); $iDb = new WDB(); $rncs = new MRncs($iDb); //jo.etablissements => insee uniquement, rncs ? //Entreprise $infosEtab = $rncs->getIdentiteEtab($siren); if ( $infosEtab === false ) { throw new SoapFault('MSG', "Cette entreprise n'est pas inscrite au RNCS ou radié depuis plus de 5 ans."); } $output->Nom = $infosEtab['raisonSociale']; //@todo personne physique $output->Sigle = $infosEtab['sigle']; $output->Enseigne = $infosEtab['enseigne']; $output->NomCommercial = $infosEtab['nomCommercial']; $output->Siren = $infosEtab['siren']; $output->NumGest = $infosEtab['numRC']; $output->RadiationDate = $infosEtab['dateRad']; $output->ImmatDate = $infosEtab['dateImma']; $output->NafCode = $infosEtab['nafEnt']; $output->NafLabel = $infosEtab['nafEntLib']; if (empty($infosEtab['dateRad']) || $infosEtab['dateRad'] = '0000-00-00') { $output->TribunalCode = $infosEtab['triCode']; //@todo $output->TribunalLabel = $infosEtab['libGreffe']; // @todo $output->FjCode = $infosEtab['cj']; $output->FjLabel = $infosEtab['cjLib']; $output->Capital = $infosEtab['capital']; $output->CapitalDev = 'EUR'; if ( !empty($infosEtab['capitalDevIso'])) { $output->CapitalDev = $infosEtab['capitalDevIso']; } $output->CapitalType = $infosEtab['capitalType']; $output->SiegeAdresseNum = intval($infosEtab['adrNumVoie']); $output->SiegeAdresseBtq = $infosEtab['adrIndRep']; $output->SiegeAdresseVoieType = $infosEtab['adrTypeVoie'] ; $output->SiegeAdresseVoieLabel = $infosEtab['adrVoie']; $output->SiegeAdresseComp = $infosEtab['adrComp']; $output->SiegeAdresseCP = $infosEtab['cp']; $output->SiegeAdresseVille = $infosEtab['commune']; $output->DateMajRCS = $infosEtab['DateMajRCS']; //Durée de la société - impossible $output->DureeDate = ''; //Date du dernier bilan - MOIS/JOUR au pire chercher dans l'annonce try { $bilanM = new Application_Model_JoBilans(); $sql = $bilanM->select(true) ->columns(array('dateExercice')) ->where('siren=?', $siren) ->order('dateExercice DESC')->limit(1); $result = $bilanM->fetchRow($sql); if ($result !== null) { $output->CompteArretMois = substr($result->dateExercice,4,2); $output->CompteArretJour = substr($result->dateExercice,6,2); } } catch(Zend_Db_Exception $e) {} //=> Avec l'adresse du premier siège $output->ConstitutionTribunalCode = ''; $output->ConstitutionTribunalLabel = ''; $iInsee = new MInsee($iDb); $dirs = $iInsee->getDirigeants($siren, false); $liste = array(); foreach ($dirs as $nb => $dir) { $dirigeant = new AvisRncsAdmin(); $dirigeant->Code = $dir['Fonction']; $dirigeant->Label = $dir['Titre']; $dirigeant->CompanyName = $dir['Societe']; $dirigeant->CompanyId = (array_key_exists('Siren', $dir) && intval($dir['Siren'])!=0) ? $dir['Siren'] : '' ; $dirigeant->Civilite = $dir['Civilite']; $dirigeant->Nom = $dir['Nom']; $dirigeant->Prenom = $dir['Prenom']; $dirigeant->NomUsage = $dir['NomUsage']; $dirigeant->NaissanceDate = $dir['NaissDate']; $dirigeant->NaissanceVille = $dir['NaissVille']; $dirigeant->NaissanceCp = $dir['NaissDepPays']; $liste[] = $dirigeant; } $output->Administration = $liste; $insee = $iInsee->getIdentiteEntreprise($siren); //Origine, code à transformer - getIdentiteEntreprise - insee $output->Origine = $insee['OrigineCreation']; //Activité réelle - getIdentiteEntreprise - insee $output->Activite = $insee['Activite']; $output->BodaccActivite = $insee['Activite']; //Date de création à l'insee - getIdentiteEntreprise - insee //@todo : Aller cherche dans les annonces bodacc création + acquisition $output->ActiviteDate = substr($insee['DateCreaEn'],0,4).'-'.substr($insee['DateCreaEn'],4,2).'-'.substr($insee['DateCreaEn'],6,2); //Type d'exploitation - getIdentiteEntreprise - insee $output->Exploitation = $insee['TypeExploitation']; //Liste des jugements $output->Evenements = array(); $evens = $rncs->getListeJugements($siren); if ( count($evens)>0 ) { foreach ( $evens as $even ) { $output->Evenements[] = $even['dateEffet'] . ' - ' . $even['libEven']; } } //Liste des dépots $output->Depots = array(); $infogreffe = new SdMetier_Infogreffe_DocAC($siren); $depots = $infogreffe->getList(); if ( count($depots)>0 ) { $i = 0; $listNumDepot = array(); foreach ( $depots as $depot ) { $acte = new AvisRncsDepot(); $acte->DepotNum = $depot->DepotNum; $acte->DepotDate = $depot->DepotDate; $acte->ActeNum = $depot->ActeNum; $acte->ActeDate = $depot->ActeDate; $acte->ActeType = $depot->ActeType; $acte->ActeTypeLabel = $depot->ActeTypeLabel; $acte->infos = $depot->infos; $result = $rncs->getListeDepots($siren, $depot->DepotDate); if (count($result)>0) { foreach ($result as $infos) { $acte->infos[] = $infos['libDepot']; } } //Acte constitutif - Statut //@todo : STATUTS CONSTITUTIFS $date = substr($depot->ActeDate,0,4); if ( in_array($depot->ActeType, array('04')) && intval($date)>1995 ) { $output->ConstitutionActeDate = $depot->ActeDate; $output->ConstitutionDepotDate = $depot->DepotDate; } $i++; if ($i < 4 || $i > count($depots)-4) { $output->Depots[] = $acte; } } } //Liste des établissements actifs au RNCS $output->Etablissements = array(); $result = $iInsee->getEtablissements($siren, '', 0, 200, 200, 0, 1); if ( count($result['reponses'])>0 ) { foreach ( $result['reponses'] as $item ) { $output->Etablissements[] = $item['Adresse'] . ' ' . $item['Adresse2'] . ' - ' . $item['CP'] . ' ' . strtoupper($item['Ville']); } } } $this->wsLog('avisrncs', $siren); return $output; } /** * RNVP * @param string $companyId * Identifiant etablissement * @param string $type (sd|siren, sd ou null par defaut) * Type de l'identifiant : * sd|null = Identifiant Scores & Decisions * siren = SIRET de l'etablissement * @throws SoapFault * @return Rnvp */ public function getRNVP($companyId, $type = null) { $this->authenticate(); $this->permission('RNVP'); // --- Identifiant SD : source + id if ($type === null) { $source = substr($companyId,0,3); $sourceId = substr($companyId,3,20); } // --- Siren elseif (strtolower($type) == 'siren') { if ( strlen($companyId) != 14 || intval($siren) == 0 ) { throw new SoapFault('ERR', 'Identifiant incorrect.'); } try { $etabM = new Application_Model_JoEtablissements(); $sql = $etabM->select(true)->columns(array('LPAD(source,3,0)', 'LPAD(source_id,20,0)')) ->where('siren=?', substr($companyId,0,9)) ->where('nic=?', substr($companyId,9,5)); $etabResult = $etabM->fetchRow($sql); if ($etabResult === null) { throw new SoapFault('MSG', 'Etablissement inconnu.'); } $source = $etabResult->source; $sourceId = $etabResult->source_id; } catch (Zend_Db_Exception $e) { if ($this->User->idClient==1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } } // Erreur else { throw new SoapFault('ERR', 'type identifiant inconnu'); } // --- Formattage pour la sortie try { $rnvpM = new Application_Model_VillesRnvpSources(); $sql = $rnvpM->select(true)->columns(array( 'L1rnvp', 'L2rnvp', 'L3rnvp', 'L4rnvp', 'L5rnvp', 'L6rnvp', 'L7rnvp', 'dateRetourRnvp', 'codeRetour', 'LPAD(Insee,5,0) as Insee', 'CorrectionImportante', 'CorrectionDouteuse', 'CQadrs', 'HexaCle', 'NumDept', 'IdHexavia', 'IdHexaposte', 'Iris_Rivoli', 'Iris_Ilot99', 'Iris_CodeIris', 'Iris_Canton', 'Cdx_Matricule', 'Cdx_V5Geo', 'Cdx_V6Geo', 'Cdx_V5Cdx', 'Cdx_V6Cdx', 'dateInsert', 'dateUpdate', ))->where('source=?', $source)->where('source_id=?', $sourceId); $rnvpResult = $rnvpM->fetchRow($sql); if ($rnvpResult === null) { throw new SoapFault('MSG', "Aucun résultat"); } $InfoRNVP = new Rnvp(); $InfoRNVP->L1 = $rnvpResult->L1rnvp; $InfoRNVP->L2 = $rnvpResult->L2rnvp; $InfoRNVP->L3 = $rnvpResult->L3rnvp; $InfoRNVP->L4 = $rnvpResult->L4rnvp; $InfoRNVP->L5 = $rnvpResult->L5rnvp; $InfoRNVP->L6 = $rnvpResult->L6rnvp; $InfoRNVP->L7 = $rnvpResult->L7rnvp; $InfoRNVP->ProcessDate = $rnvpResult->dateRetourRnvp; $InfoRNVP->ProcessCode = $rnvpResult->codeRetour; switch($rnvpResult->codeRetour) { case 'ND': $InfoRNVP->ProcessLabel = "ND"; break; case 'KO': $InfoRNVP->ProcessLabel = "KO"; break; case 'OK': $InfoRNVP->ProcessLabel = "Adresse correcte"; if ($rnvpResult->CorrectionImportante == 'I') { $InfoRNVP->ProcessLabel = "Adresse avec correction(s) importante(s)"; } if ($rnvpResult->CorrectionDouteuse == 'D') { $InfoRNVP->ProcessLabel = "Adresse mais correction(s) douteuse(s)"; } break; } $InfoRNVP->QualityCode = $rnvpResult->CQadrs; // Label CQadrs $InfoRNVP->QualityLabel = ''; $tabCQAdrs = array( '10' => "Adresse correcte", '20' => "Adresse correcte (Voie non reconnue, mais il s'agit d'un cedex ou BP)", '21' => "Petite ville, Numéro de facade hors borne.", '22' => "Petite ville, Numéro de facade absent (le reste de l'adresse est correcte)", '23' => "Grande ville, Numéro de facade hors borne.", '24' => "Grande ville, Numéro de facade absent (le reste de l'adresse est correcte)", '30' => "Petite ville, voie non reconnue", '31' => "Petite ville, voie non reconnue (info quartier reconnu, ne permettant pas de déduire la voie)", '40' => "Petite ville, voie absente (info quartier reconnu, ne permettant pas de déduire la voie)", '41' => "Petite ville, voie absente", '50' => "Grande ville, voie non reconnue", '51' => "Grande ville, voie non reconnue (info quartier reconnu, ne permettant pas de déduire la voie)", '60' => "Grande ville, voie absente (info quartier reconnu, ne permettant pas de déduire la voie)", '61' => "Grande ville, voie absente", '70' => "Cp/Ville non corrigeable (voie présente)", '80' => "Cp/Ville non corrigeable (voie absente)", '90' => "Etranger détecté", ); if( array_key_exists($rnvpResult->CQadrs, $tabCQAdrs) ) { $InfoRNVP->QualityLabel = $tabCQAdrs[$rnvpResult->CQadrs]; } $InfoRNVP->GeoInseeCommune = $rnvpResult->Insee; $InfoRNVP->GeoHexavia = $rnvpResult->IdHexavia; $InfoRNVP->GeoHexapost = $rnvpResult->IdHexaposte; $InfoRNVP->GeoHexacle = $rnvpResult->HexaCle; $InfoRNVP->GeoDepartement = $rnvpResult->NumDept; $InfoRNVP->GeoRivoliCode = $rnvpResult->Iris_Rivoli; $InfoRNVP->GeoIlot = $rnvpResult->Iris_Ilot99; $InfoRNVP->GeoIris = $rnvpResult->Iris_CodeIris; $InfoRNVP->GeoCanton = $rnvpResult->Iris_Canton; $InfoRNVP->CedexaMatricule = $rnvpResult->Cdx_Matricule; $InfoRNVP->CedexaGeoL5 = $rnvpResult->Cdx_V5Geo; $InfoRNVP->CedexaGeoL6 = $rnvpResult->Cdx_V6Geo; $InfoRNVP->CedexaCdxL5 = $rnvpResult->Cdx_V5Cdx; $InfoRNVP->CedexaCdxL6 = $rnvpResult->Cdx_V6Cdx; $InfoRNVP->DateInsert = $rnvpResult->dateInsert; $InfoRNVP->DateUpdate = $rnvpResult->dateUpdate; $this->wsLog('rnvp', 0, $companyId); return $InfoRNVP; } catch (Zend_Db_Exception $e) { if ($this->User->idClient==1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } } /** * Liste des privilèges * @param string $companyId * @throws SoapFault * @return PrivilegeList */ public function getPrivilegeList($companyId) { $this->authenticate(); if ( strlen($companyId) != 9 ) { throw new SoapFault('ERR', 'Identifiant incorrect.'); } // --- Durée de vie $privSecuLifetime = 900; $privTresLifetime = 1460; $privSql = "SELECT id, dateEven, greffe , numDebiteur, sirenage, typeEven, dateFraiche, codeRev, debRaisonSociale, debSigle, debCiv, debNom, debPrenom, debConjoint, debUsage, debEnseigne, debNumVoie, debTypVoie, debLibVoie, debAdrComp, debCP, debVille, debPays, insType, insLib, insNum, insDate, insObjet, insMontant, insDev, insDateEch, insDateFin, creNom, creNumVoi, creTypVoi, creLibVoi, creAdrComp1, creAdrComp2, creCP, creVille, crePays, creAutres, radDate, radMention, radPartiel, radPartMt, radDev, radDiv, idFichier, DATE_FORMAT(dateInsert,'%Y-%m-%d') AS dateInsert FROM jo.greffes_privileges WHERE siren=$companyId AND ( (insType='03' AND DATEDIFF(NOW(),insDate) <= $privSecuLifetime) OR (insType='04' AND DATEDIFF(NOW(),insDate) <= $privTresLifetime) ) ORDER BY insDate DESC;"; try { $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $privResult = $db->fetchAll($privSql, null, Zend_Db::FETCH_OBJ); } catch(Zend_Db_Exception $e) { if ($this->User->idClient==1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } $output = new PrivilegeList(); $output->NbTotal = 0; $output->MtTotal = 0; $output->Cumul = array(); $privileges = array(); $cumul = array(); if (count($privResult) > 0) { foreach($privResult as $p) { // --- Cumul des privileges par type (Nb, Montant) $output->NbTotal++; $output->MtTotal+= $p->insMontant; if ( array_key_exists($p->insType, $cumul) ) { $cumul[$p->insType]['Nb']++; $cumul[$p->insType]['Mt'] = $cumul[$p->insType]['Mt'] + $p->insMontant; } else { $cumul[$p->insType]['Nb'] = 1; $cumul[$p->insType]['Mt'] = $p->insMontant; } // --- Liste des privileges $privilege = new Privilege(); $privilege->Id = $p->id; $privilege->Type = $p->insType; $privilege->TypeLabel = ''; switch ($p->insType) { case '03': $privilege->TypeLabel = 'Privilèges de la sécurité sociale et des régimes complémentaires'; break; case '04': $privilege->TypeLabel = 'Privilèges du trésor public'; break; } $privilege->Date = $p->insDate; $privilege->Mt = $p->insMontant; $privilege->CreancierNom = $p->creNom; $privilege->CreancierAdresse1 = trim($p->creNumVoi); $privilege->CreancierAdresse1.= ' '.trim($p->creTypVoi); $privilege->CreancierAdresse1.= ' '.trim($p->creLibVoi); $privilege->CreancierAdresse2 = $p->creAdrComp1; $privilege->CreancierAdresse3 = $p->creAdrComp2; $privilege->CreancierCP = $p->creCP; $privilege->CreancierVille = $p->creVille; $privilege->CreancierPays = $p->crePays; $privilege->CreancierAutres = $p->creAutres; $privileges[] = $privilege; } } $output->List = $privileges; if (count($cumul) > 0 ) { foreach ($cumul as $k => $v) { $c = new PrivilegeCumul(); $c->Type = $k; $c->Nb = $v['Nb']; $c->Mt = $v['Mt']; $output->Cumul[] = $c; } } // --- Log $this->wsLog('privlist', $companyId); return $output; } /** * Détail d'un privilège * @param string $companyId * @param int $id * @throws SoapFault * @return PrivilegeDetail */ public function getPrivilegeDetail($companyId, $id) { $this->authenticate(); if ( strlen($companyId) != 9 ) { throw new SoapFault('ERR', 'Identifiant incorrect.'); } $privSql = "SELECT id, dateEven, greffe , numDebiteur, sirenage, typeEven, dateFraiche, codeRev, debRaisonSociale, debSigle, debCiv, debNom, debPrenom, debConjoint, debUsage, debEnseigne, debNumVoie, debTypVoie, debLibVoie, debAdrComp, debCP, debVille, debPays, insType, insLib, insNum, insDate, insObjet, insMontant, insDev, insDateEch, insDateFin, creNom, creNumVoi, creTypVoi, creLibVoi, creAdrComp1, creAdrComp2, creCP, creVille, crePays, creAutres, radDate, radMention, radPartiel, radPartMt, radDev, radDiv, idFichier, DATE_FORMAT(dateInsert,'%Y-%m-%d') AS dateInsert FROM jo.greffes_privileges WHERE siren=$companyId AND id=$id"; try { $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $p = $db->fetchRow($privSql, null, Zend_Db::FETCH_OBJ); } catch(Zend_Db_Exception $e) { if ($this->User->idClient==1) { throw new SoapFault('ERR', $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } $iRncs = new MRncs(); $privilege = new PrivilegeDetail(); $privilege->Id = $p->id; $privilege->Type = $p->insType; $privilege->TypeLabel = ''; switch ($p->insType) { case '03': $privilege->TypeLabel = 'Privilèges de la sécurité sociale et des régimes complémentaires'; break; case '04': $privilege->TypeLabel = 'Privilèges du trésor public'; break; } $privilege->Num = $p->insNum; $privilege->Objet = $p->insObjet; $privilege->Date = $p->insDate; $privilege->DateFresh = $p->dateFraiche; $privilege->DateInsert = $p->dateInsert; $privilege->DateEcheance = $p->insDateEch; $privilege->DateFin = $p->insDateFin; $privilege->Mt = $p->insMontant; $privilege->Devise = $p->insDev; $privilege->DebiteurNum = $p->numDebiteur; $privilege->Greffe = $p->greffe; $privilege->GreffeLabel = $iRncs->getLibTribunal($p->greffe); $privilege->RadiationDate = $p->radDate; $privilege->RadiationMention = $p->radMention; $privilege->RadiationPartiel = $p->radPartiel; $privilege->RadiationMt = $p->radPartMt; $privilege->RadiationDevise = $p->radDev; $privilege->CreancierNom = $p->creNom; $privilege->CreancierAdresse1 = trim($p->creNumVoi); $privilege->CreancierAdresse1.= ' '.trim($p->creTypVoi); $privilege->CreancierAdresse1.= ' '.trim($p->creLibVoi); $privilege->CreancierAdresse2 = $p->creAdrComp1; $privilege->CreancierAdresse3 = $p->creAdrComp2; $privilege->CreancierCP = $p->creCP; $privilege->CreancierVille = $p->creVille; $privilege->CreancierPays = $p->crePays; $privilege->CreancierAutres = $p->creAutres; // --- Log $this->wsLog('privdetail', $companyId, $id); return $privilege; } protected function getPrivilegeHisto($companyId) { $this->authenticate(); if ( strlen($companyId) != 9 ) { throw new SoapFault('ERR', 'Identifiant incorrect.'); } // Liste de tous les privileges actif et inactif // --- Log $this->wsLog('privhisto', $companyId); } /** * Formatte les informations de calculIndiscore * @param array $infos * @return stdClass */ protected function formatIndiscore($infos) { $output = new stdClass(); foreach($infos as $key => $value){ if ($key=='paiements'){ $parMont = $value['parMont']; $parTrim = $value['parTrim']; $tabMont = array(); foreach($parMont as $parMontK => $parMontV){ $paiementMont = new IndiscorePaiementDetail(); $paiementMont->id = $parMontK; $paiementMont->nb = $parMontV['nb']; if (array_key_exists('d=180', $parMontV)){ $paiementMont->d180 = $parMontV['d=180']; } if (array_key_exists('d=150', $parMontV)){ $paiementMont->d150 = $parMontV['d=150']; } if (array_key_exists('d=120', $parMontV)){ $paiementMont->d120 = $parMontV['d=120']; } if (array_key_exists('d=90', $parMontV)){ $paiementMont->d90 = $parMontV['d=90']; } if (array_key_exists('d=60', $parMontV)){ $paiementMont->d60 = $parMontV['d=60']; } if (array_key_exists('d=30', $parMontV)){ $paiementMont->d30 = $parMontV['d=30']; } $tabMont[] = $paiementMont; } $tabTrim = array(); foreach($parTrim as $parTrimK => $parTrimV){ $paiementTrim = new IndiscorePaiementDetail(); $paiementTrim->id = $parTrimK; $paiementTrim->nb = $parTrimV['nb']; if (array_key_exists('d=180', $parTrimV)){ $paiementTrim->d180 = $parTrimV['d=180']; } if (array_key_exists('d=150', $parTrimV)){ $paiementTrim->d150 = $parTrimV['d=150']; } if (array_key_exists('d=120', $parTrimV)){ $paiementTrim->d120 = $parTrimV['d=120']; } if (array_key_exists('d=90', $parTrimV)){ $paiementTrim->d90 = $parTrimV['d=90']; } if (array_key_exists('d=60', $parTrimV)){ $paiementTrim->d60 = $parTrimV['d=60']; } if (array_key_exists('d=30', $parTrimV)){ $paiementTrim->d30 = $parTrimV['d=30']; } $tabTrim[] = $paiementTrim; } $paiement = new IndiscorePaiement(); $paiement->parMont = $tabMont; $paiement->parTrim = $tabTrim; $output->paiements = $paiement; } elseif ($key=='Notes_Structure') { $notesStructure = new IndiscoreNotesStructure(); $notesStructure->activite = $value['activite']; $notesStructure->naf4 = $value['naf4']; $notesStructure->age = $value['age']; $notesStructure->capital = $value['capital']; $notesStructure->effectif = $value['effectif']; $notesStructure->fj = $value['fj']; $notesStructure->localite = $value['localite']; $notesStructure->singulier = $value['singulier']; $output->Notes_Structure = $notesStructure; } elseif ($key=='tabBilans') { $tabRet = array(); foreach($value as $bilan) { $element = new ListeBilans(); $element->dateProvPartenaire = $bilan['dateProvPartenaire']; //@todo : date $element->dateInsert = $bilan['dateInsert']; //@todo : date $element->typeBilan = $bilan['typeBilan']; $element->dureeExercice = $bilan['dureeExercice']; $element->dateExercice = $bilan['dateExercice']; //@todo : date $element->millesime = $bilan['millesime']; $element->dateExercicePre = $bilan['dateExercicePre']; //@todo : date $element->dureeExercicePre = $bilan['dureeExercicePre']; $element->monnaie = $bilan['monnaie']; $element->source = $bilan['source']; $tabRet[] = $element; } $output->tabBilans = $tabRet; } elseif ($key=='tabBilan') { $tabRet = array(); foreach($value as $bilan){ $resultBilan = new Bilan(); $tabPoste = array(); foreach($bilan as $bilan_key => $bilan_value){ if(!in_array($bilan_key, array('SIREN', 'DATE_FRAICHE_BILAN', 'DATE_CLOTURE', 'DATE_CLOTURE_PRE', 'DUREE_MOIS', 'DUREE_MOIS_PRE', 'MONNAIE', 'CONSOLIDE', 'MONNAIE_ORI', 'MONNAIE_LIV_UNITE', 'SOURCE', 'devise'))){ $resultPoste = new BilanPoste(); $resultPoste->id = $bilan_key; $resultPoste->val = $bilan_value; $tabPoste[] = $resultPoste; } else { $resultBilan->$bilan_key = $bilan_value; } } $resultBilan->POSTES = $tabPoste; $tabRet[] = $resultBilan; } $output->tabBilan = $tabRet; } elseif ($key=='tabInfosNotations') { $infosNotation = new IndiscoreInfosNotations(); $infosNotation->SituationFinanciere = $value['SituationFinanciere']; $infosNotation->Notation = $value['Notation']; $infosNotation->ProbabiliteDefaut = $value['ProbabiliteDefaut']; $output->tabInfosNotations = $infosNotation; } elseif ($key=='tabImportExport') { $tabRet = array(); foreach($value as $element){ $importExport = new IndiscoreImportExport(); $importExport->importExport = $element['importExport']; $importExport->annee = $element['annee']; $importExport->rangNational = $element['rangNational']; $importExport->deptSiege = $element['deptSiege']; $tabRet[] = $importExport; } $output->tabImportExport = $tabRet; } elseif ($key=='tabCommentaires') { $tab = array(); if (count($value)>0) { foreach($value as $comment) { $tab[] = Scores_Locale_String::fixEncoding($comment); } } $output->tabCommentaires = $tab; } elseif ($key=='tabVariables') { $tab = $value['CA_Y']; $tabVar = array(); if (count($tab)>0) { foreach($tab as $varName => $varVal){ $var = new CA_Y(); $var->id = $varName; $var->val = $varVal; $tabVar[] = $var; } } $variables = new IndiscoreVariables(); $variables->CA_Y = $tabVar; $output->tabVariables = $variables; } elseif ($key=='Bilans') { $tab = array(); foreach($value as $item) { $objet = new IndiscoreBilans(); $objet->Millesime = $item['Millesime']; $objet->FraisPerso = $item['FraisPerso']; $objet->CA = $item['CA']; $objet->EBE = $item['EBE']; $objet->TxInvest = $item['TxInvest']; $objet->TxEndett = $item['TxEndett']; $objet->DettesCT = $item['DettesCT']; $objet->FraisFi = $item['FraisFi']; $objet->BFR = $item['BFR']; $objet->FR = $item['FR']; $objet->FondsPr = $item['FondsPr']; $objet->DelaiCli = $item['DelaiCli']; $objet->DelaiFour = $item['DelaiFour']; $tab[] = $objet; } $output->$key = $tab; } else { $output->$key = $value; } } return $output; } /** * Evaluation IndiScore * @param string $companyId * Siren de l'entreprise * @return stdClass */ protected function getIndiScore($companyId) { $this->authenticate(); $this->permission('INDISCORE'); /* Evaluation indiscore d'une entreprise Ne pas renvoyer les commentaires tabCommentaires */ $siren = substr($companyId, 0, 9); if (intval($siren) < 100 ) { $this->sendError('1010'); } $scoring = new SdMetier_Scoring_Base(); $indiscoreStruct = $scoring->calculIndiScore($siren); $output = new Indiscore(); $output = $this->formatIndiscore($indiscoreStruct); return $output; } protected function getReportSynthese($companyId) { $this->authenticate(); $this->permission('INDISCORE2'); $siren = substr($companyId, 0, 9); if (intval($siren) < 100 ) { $this->sendError('1010'); } $reportStruct = new ReportSynthese(); $identiteStruct = $this->getIdentite($siren); $scoring = new SdMetier_Scoring_Base(); //$scoring->injectIdentite(); $indiscoreStruct = $scoring->calculIndiScore($siren); //$ratiosStruct = $this->getRatios($siren); } protected function getReportComment($companyId) { $this->authenticate(); $this->permission('INDISCORE3'); $reportStruct = new Report(); $scoring = new SdMetier_Scoring_Base(); $indiscoreStruct = $scoring->calculIndiScore($siren); /* Commentaires suivant niveau $identite = $ws->getIdentite($siren); $indiscore = $ws->getIndiScore($siren); $infos = $ws->getRatios($siren, 'indiscore2'); ou - $result->Identite = $this->getIdentite($siren, $id=0); $result->Indiscore = $this->getIndiScore($siren, 0, $nivComment, $plus, $ref, $encours, $email); $result->Ratios = $this->getRatios($siren, $page="rapport$niveau"); $result->Dirigeants = $this->getDirigeants($siren, false); $result->Liens = $this->getLiens($siren, true); ou $result->Identite = $this->getIdentite($siren, $id=0); $result->Indiscore = $this->getIndiScore($siren, 0, $nivComment, $plus, $ref, $encours, $email); $result->Ratios = $this->getRatios($siren, $page="rapport$niveau"); $result->Dirigeants = $this->getDirigeants($siren, false); $result->Liens = $this->getLiens($siren, true); $result->Annonces = $this->getAnnonces($siren, $filtre, $idAnn); */ return $reportStruct; } protected function getValo(){} } ?>