2815 lines
96 KiB
PHP
2815 lines
96 KiB
PHP
<?php
|
|
require_once __DIR__ . '/Types.php';
|
|
|
|
class Interne extends Scores_Ws_Server
|
|
{
|
|
/**
|
|
* Retourne le détails des privilèges
|
|
* @param string $siren
|
|
* @param array $tabTypes
|
|
* @return PrivilegesDetailReturn
|
|
*/
|
|
public function getPrivilegesDetail($siren, $tabTypes=array('03','04'))
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
if (empty($tabTypes)) $tabTypes = array('03','04');
|
|
Metier_Util_Log::write('I',"Liste des privilèges detail sur $siren ".print_r($tabTypes, true),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$iPriv = new Metier_Partenaires_MPrivileges();
|
|
$ret = $iPriv->getPrivilegesDetail($siren, $tabTypes); //@todo : date
|
|
|
|
$tabRet = array();
|
|
if (count($ret)>0) {
|
|
foreach ($ret as $item ) {
|
|
$privileges = new PrivilegesDetail();
|
|
$privileges->numDebiteur = $item['numDebiteur'];
|
|
$privileges->greffe = $item['greffe'];
|
|
$privileges->greffeLib = $item['greffeLib'];
|
|
$privileges->dateEven = $item['dateEven'];
|
|
$privileges->dateFraiche = $item['dateFraiche'];
|
|
$privileges->dateSD = $item['dateSD'];
|
|
$privileges->insType = $item['insType'];
|
|
$privileges->insTypeLib = $item['insTypeLib'];
|
|
$privileges->insNum = $item['insNum'];
|
|
$privileges->insDate = $item['insDate'];
|
|
$privileges->insDateEch = $item['insDateEch'];
|
|
$privileges->insObjet = $item['insObjet'];
|
|
$privileges->insMontant = $item['insMontant'];
|
|
$privileges->insDev = $item['insDev'];
|
|
$privileges->insDateFin = $item['insDateFin'];
|
|
$privileges->radDate = $item['radDate'];
|
|
$privileges->radMention = $item['radMention'];
|
|
$privileges->radPartiel = $item['radPartiel'];
|
|
$privileges->radPartMt = $item['radPartMt'];
|
|
$privileges->radDev = $item['radDev'];
|
|
$privileges->creNom = $item['creNom'];
|
|
$privileges->creAdresse1 = $item['creAdresse1'];
|
|
$privileges->creAdresse2 = $item['creAdresse2'];
|
|
$privileges->creAdresse3 = $item['creAdresse3'];
|
|
$privileges->creCP = $item['creCP'];
|
|
$privileges->creVille = $item['creVille'];
|
|
$privileges->crePays = $item['crePays'];
|
|
$privileges->creAutres = $item['creAutres'];
|
|
$tabRet[] = $privileges;
|
|
}
|
|
}
|
|
$this->wsLog('privdetail', $siren, join(',',$tabTypes));
|
|
$output = new PrivilegesDetailReturn();
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Retourne les privilèges cumulés
|
|
* @param string $siren
|
|
* @param array $tabTypes
|
|
* @return PrivilegesCumulReturn
|
|
*/
|
|
public function getPrivilegesCumul($siren, $tabTypes=array('03','04'))
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
if (empty($tabTypes)) $tabTypes = array('03','04');
|
|
Metier_Util_Log::write('I',"Liste des privilèges cumul sur $siren ".print_r($tabTypes, true),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$iPriv = new Metier_Partenaires_MPrivileges();
|
|
$ret = $iPriv->getPrivilegesCumul($siren, $tabTypes);
|
|
$tabRet = array();
|
|
|
|
if (isset($ret['03']) && count($ret['03']>0)){
|
|
$value = $ret['03'];
|
|
$priv = new PrivilegesCumul();
|
|
$priv->insType = '03';
|
|
$priv->nb = $value['nb'];
|
|
$priv->insTypeLib = $value['insTypeLib'];
|
|
$priv->dateFraiche = $value['dateFraiche']; //@todo : date
|
|
$priv->dateDerInsc = $value['dateDerInsc']; //@todo : date
|
|
$priv->nomDerCre = $value['nomDerCre'];
|
|
$priv->numDebiteur = $value['numDebiteur'];
|
|
$priv->greffeLib = $value['greffeLib'];
|
|
$priv->dateMajSD = $value['dateMajSD']; //@todo : date
|
|
$priv->insCumul = $value['insCumul'];
|
|
$tabRet[] = $priv;
|
|
}
|
|
|
|
if (isset($ret['04']) && count($ret['04']>0)){
|
|
$value = $ret['04'];
|
|
$priv = new PrivilegesCumul();
|
|
$priv->insType = '04';
|
|
$priv->nb = $value['nb'];
|
|
$priv->insTypeLib = $value['insTypeLib'];
|
|
$priv->dateFraiche = $value['dateFraiche']; //@todo : date
|
|
$priv->dateDerInsc = $value['dateDerInsc']; //@todo : date
|
|
$priv->nomDerCre = $value['nomDerCre'];
|
|
$priv->numDebiteur = $value['numDebiteur'];
|
|
$priv->greffeLib = $value['greffeLib'];
|
|
$priv->dateMajSD = $value['dateMajSD']; //@todo : date
|
|
$priv->insCumul = $value['insCumul'];
|
|
$tabRet[] = $priv;
|
|
}
|
|
|
|
//Log
|
|
foreach ($tabTypes as $type)
|
|
{
|
|
$this->wsLog('privcumul', $siren, $type);
|
|
}
|
|
|
|
$output = new PrivilegesCumulReturn();
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Liste les mandataires correspondant à un nom donné
|
|
* @param mixed $codeTribunal Identifiants BODACC du tribunal ou tableau d'Identifiants numériques des cours d'appel
|
|
* @param array $type Type de mandataire (A)dministrateur, (M)andataire, (O)ppositions, (N)otaires, a(V)ocat
|
|
* @param int $cpDep Code postal ou département du mandataire
|
|
* @return SearchMandatairesReturn
|
|
*/
|
|
public function searchMandataires($nom, $type=array('A','M'), $cpDep=0)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
if (empty($type)) $type = array('A','M');
|
|
if (empty($cpDep)) $cpDep = 0;
|
|
$tabRet = array();
|
|
|
|
Metier_Util_Log::write('I',"Recherche de Mandataires '$nom' (Dep=$cpDep)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabTmp = $iInsee->searchMandataires($nom, true, $type, $cpDep);
|
|
|
|
foreach ($tabTmp as $i=>$mand)
|
|
{
|
|
$mandataire = new SearchMandataire();
|
|
$mandataire->id = 'm'.$i;
|
|
$mandataire->mand = $mand;
|
|
$tabRet[] = $mandataire;
|
|
|
|
}
|
|
$output = new SearchMandatairesReturn();
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Retourne la liste des tribunaux ou Compétences demandées
|
|
* @param array|string $tabTypes Tableau des types de Compétences demandés 'C':Commerce, 'I':Instance, 'G':TGI, 'A':Préfectures, 'B':Sous-préf, 'D':Tribunal Administratif, 'H':Prud'hommes, 'L': Cour d'Appel, 'M': Tribunal Mixte, 'O':CCI, 'V': Cour Administrative d'Appel
|
|
* @return TribunauxReturn
|
|
**/
|
|
public function getTribunaux($tabTypes)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
if (empty($tabTypes)) $tabTypes = array();
|
|
if (is_string($tabTypes)) $tabTypes = (array)$tabTypes;
|
|
|
|
$iBodacc = new Metier_Bodacc_MBodacc();
|
|
Metier_Util_Log::write('I',"Liste des tribunaux demandées",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$tabTmp = $iBodacc->getListeTribunaux();
|
|
//@todo : Retourner liste en ordre alphabétique
|
|
$tabRet = array();
|
|
if (count($tabTypes)==0) {
|
|
foreach ($tabTmp as $i => $tribunal){
|
|
$tri = new Tribunal();
|
|
$tri->code = $i;
|
|
$tri->nom = $tribunal['nom'];
|
|
$tabRet[] = $tri;
|
|
}
|
|
} else {
|
|
foreach ($tabTmp as $i=>$tribunal){
|
|
$type = substr($i,-1);
|
|
if ( in_array($type, $tabTypes) ){
|
|
$tri = new Tribunal();
|
|
$tri->code = $i;
|
|
$tri->nom = $tribunal['nom'];
|
|
$tabRet[] = $tri;
|
|
}
|
|
}
|
|
}
|
|
$this->wsLog('tribunaux', '', print_r($tabTypes,1));
|
|
$output = new TribunauxReturn();
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Enregistre une action utilisateur pour la facturation
|
|
* @param string $page
|
|
* @param string $siret
|
|
* @param int $id
|
|
* @param string $ref
|
|
* @return void
|
|
*/
|
|
public function setLog($page, $siret, $id=0, $ref='')
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
if (empty($id)) $id = 0;
|
|
if (empty($ref)) $ref = '';
|
|
if ( $id!=0 ) {
|
|
$ref2=''.$id.'/'.$ref;
|
|
} else {
|
|
$ref2=$ref;
|
|
}
|
|
$this->wsLog($page, $siret, $ref2);
|
|
Metier_Util_Log::write('I',"Insertion d'un log pour la page $page $siret $ref2",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
}
|
|
|
|
/**
|
|
* Récupère le mandataire par son id
|
|
* @param int $idMand Identifiant du mandataire
|
|
* @return MandataireReturn
|
|
*/
|
|
public function getMandataire($idMand)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
|
|
Metier_Util_Log::write('I',"Donne le Mandataires correspondant à $idMand",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabRet = $iInsee->getMandataire($idMand);
|
|
$mandataire = new MandataireDetail();
|
|
$mandataire->Nom = $tabRet['Nom'];
|
|
$mandataire->Prenom = $tabRet['Prenom'];
|
|
$mandataire->tribunal = $tabRet['tribunal'];
|
|
$mandataire->adresse = $tabRet['adresse'];
|
|
$mandataire->adresseComp = $tabRet['adresseComp'];
|
|
$mandataire->ville = $tabRet['ville'];
|
|
$mandataire->email = $tabRet['email'];
|
|
$mandataire->web = $tabRet['web'];
|
|
$mandataire->contact = $tabRet['contact'];
|
|
$output = new MandataireReturn();
|
|
$output->error = $error;
|
|
$output->result = $mandataire;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Liste les mandataires compétentes pour une cours d'appel donnée
|
|
* @param mixed $codeTribunal Identifiants BODACC du tribunal ou tableau d'Identifiants numériques des cours d'appel
|
|
* @param array $type Type de mandataire (A)dministrateur, (M)andataire, (O)ppositions, (N)otaires, a(V)ocat
|
|
* @return MandatairesReturn
|
|
*/
|
|
public function getMandataires($codeTribunal=0, $type=array('A','M'))
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$error = new ErrorType();
|
|
$trib = serialize($codeTribunal);
|
|
Metier_Util_Log::write('I',"Liste des Mandaitaires ou Administrateur du Tribunal/Cours d'Appel $trib demandé",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
if (!is_array($codeTribunal) && strlen($codeTribunal)>3 && $codeTribunal*1==0)
|
|
{
|
|
// $codeTribunal est un identifiant de tribunal
|
|
$iBodacc = new Metier_Bodacc_MBodacc();
|
|
$tabTmp = $iInsee->getMandataires(array($iBodacc->getTribunalIdCA($codeTribunal)), true, $type);
|
|
}
|
|
elseif ($codeTribunal*1==0)
|
|
{
|
|
// On veut tous les mandataires
|
|
$tabTmp = $iInsee->getMandataires(array(), true, $type);
|
|
}
|
|
elseif (is_array($codeTribunal))
|
|
{
|
|
// On veut les mandataires d'une CA
|
|
$tabTmp = $iInsee->getMandataires($codeTribunal, true, $type);
|
|
}
|
|
$tabRet = array();
|
|
foreach ($tabTmp as $i=>$mand){
|
|
$mandataire = new Mandataire();
|
|
$mandataire->id = 'm'.$i;
|
|
$mandataire->mand = $mand;
|
|
$tabRet[]= $mandataire;
|
|
}
|
|
$output = new MandatairesReturn();
|
|
$output->error = $error;
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Retourne la liste des conventions
|
|
* @param string $siren
|
|
* @return ListeConventionsReturn
|
|
*/
|
|
public function getListeConventions($siren)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
$tabRet = array();
|
|
|
|
Metier_Util_Log::write('I',"Liste des conventions demandée pour le siren $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
if (strlen($siren)<>9){
|
|
Metier_Util_Log::write('W', "Siren/Siret $siren incorrect", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 102;
|
|
$error->errmsg = 'Siren Siret inexistant';
|
|
|
|
} elseif ($siren*1==0){
|
|
|
|
Metier_Util_Log::write('W', "Siren $siren inexistant", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 102;
|
|
$error->errmsg = 'Siren inexistant';
|
|
|
|
} else {
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabIdentite = $iInsee->getIdentiteEntreprise($siren);
|
|
|
|
if (empty($tabIdentite) && isset($tabIdentite['erreur']) &&
|
|
$tabIdentite['erreur']<>''){
|
|
|
|
Metier_Util_Log::write('W', "Siren $siren non présent en base", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 102;
|
|
$error->errmsg = 'Siren inexistant';
|
|
|
|
} else {
|
|
|
|
$naf = $tabIdentite['NafEnt'];
|
|
$trancheEffectif = $tabIdentite['EffEnTr'];
|
|
$effectif = $tabIdentite['Effectif'];
|
|
$fj = $tabIdentite['entreprise']['FJCodeEntrep'];
|
|
|
|
$isolv = new Metier_Scores_MSolvabilite($siren, $naf, $trancheEffectif,
|
|
$effectif, $tabIdentite['CP'], $fj, $tabIdentite['Capital'],
|
|
$tabIdentite['CapitalDev'], $tabIdentite['DateCreaEn'],
|
|
$tabIdentite['DateCreaEt']
|
|
);
|
|
$noteStructure = $isolv->getSolvabilite();
|
|
$naf4 = $isolv->getNaf4($naf);
|
|
|
|
$tabTmp = $iInsee->listeConventions($naf4, $tabIdentite['Dept']);
|
|
foreach ($tabTmp as $conv)
|
|
{
|
|
$convention = new Convention();
|
|
$convention->idCC = $conv['id CC'];
|
|
$convention->nomCC = $conv['nom CC'];
|
|
$convention->infoCC = $conv['infoCC'];
|
|
$convention->editorCC = $conv['editeur CC'];
|
|
$convention->nbPageCC = $conv['nb page CC'];
|
|
$convention->isbnCC = $conv['isbn CC'];
|
|
$convention->dateCC = $conv['date edition CC'];
|
|
$convention->joCCmaj = $conv['joCCmaj'];
|
|
$tabRet[] = $convention;
|
|
}
|
|
$this->wsLog('conventions',$siren);
|
|
}
|
|
}
|
|
|
|
$output = new ListeConventionsReturn();
|
|
$output->error = $error;
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Donne la cours d'appel d'un tribunal par son code
|
|
* @param string $codeTribunal Code BODACC sur 6 caractères du tribunal
|
|
* @return int
|
|
**/
|
|
public function getIdCoursAppel($codeTribunal)
|
|
{
|
|
$this->authenticate();
|
|
$iBodacc = new Metier_Bodacc_MBodacc();
|
|
return $iBodacc->getTribunalIdCA($codeTribunal);
|
|
}
|
|
|
|
/**
|
|
* Récupère le contenu d'une annonce issue de la collecte
|
|
* @param string $idAnn
|
|
* @param string $siret
|
|
* @return AnnonceCollecteReturn
|
|
*/
|
|
public function getAnnonceCollecte($idAnn, $siret)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
$annonceCollecte = new AnnonceCollecte();
|
|
$siren = substr($siret,0,9)*1;
|
|
if (!$this->checkEdition()) {
|
|
|
|
$error->errnum = 0;
|
|
$error->errmsg = 'Code Client Incorrect';
|
|
|
|
} else {
|
|
|
|
$iDb = new Metier_Util_Db();
|
|
Metier_Util_Log::write('I',"Lecture de l'annonce collectée n°$idAnn ($siret)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$idAnn = preg_replace('/^0\./','', ''.$idAnn) * 1;
|
|
if ($idAnn>0)
|
|
{
|
|
$res = $iDb->select('jo.annonces',
|
|
'id, siren, sirenValide, typeEven, strEven, raisonSociale, adresse, codePostal, ville, dateJugement, dateCessationPaiement, dateEffetFinP, numero, inter1type, inter1id, inter1nom, inter2type, inter2id, inter2nom, inter3type, inter3id, inter3nom, inter4type, inter4id, inter4nom, tribunal, montant, actionsNb, complement, infosBrutes, nouvActivite, nouvDir, nouvAdr, nouvFJ, annonce, source, parutionIdJal, parutionNum, dateSource, idSaisie, idAnnonce, dateInsert',
|
|
"id=$idAnn", false, MYSQL_ASSOC
|
|
);
|
|
if (count($res)>0)
|
|
{
|
|
$ann = $res[0];
|
|
$annonceCollecte->id = $ann['id'];
|
|
$annonceCollecte->siren = $ann['siren'];
|
|
$annonceCollecte->raisonSociale = $ann['raisonSociale'];
|
|
$annonceCollecte->adresse = $ann['adresse'];
|
|
$annonceCollecte->codePostal = $ann['codePostal'];
|
|
$annonceCollecte->ville = $ann['ville'];
|
|
$annonceCollecte->dateJugement = $ann['dateJugement'];
|
|
|
|
//@todo : Les libellées ne sont pas présent LibEven
|
|
$tabEven = array();
|
|
$annonceEvenement = new AnnonceEvenement();
|
|
$annonceEvenement->CodeEven = $ann['typeEven'];
|
|
$annonceEvenement->LibEven = '';
|
|
$tabEven[] = $annonceEvenement;
|
|
if (!empty($ann['strEven'])){
|
|
foreach ( explode(';',$ann['strEven']) as $code )
|
|
{
|
|
$annonceEvenement = new AnnonceEvenement();
|
|
$annonceEvenement->CodeEven = $code;
|
|
$annonceEvenement->LibEven = '';
|
|
$tabEven[] = $annonceEvenement;
|
|
}
|
|
}
|
|
|
|
$annonceCollecte->even = $tabEven;
|
|
$annonceCollecte->dateSource = $ann['dateSource'];
|
|
$annonceCollecte->dateCessationPaiement = $ann['dateCessationPaiement'];
|
|
$annonceCollecte->dateEffetFinP = $ann['dateEffetFinP'];
|
|
$annonceCollecte->tribunal = $ann['tribunal'];
|
|
$annonceCollecte->numero = $ann['numero'];
|
|
$annonceCollecte->montant = $ann['montant'];
|
|
$annonceCollecte->actionsNb = $ann['actionsNb'];
|
|
$annonceCollecte->inter1type = $ann['inter1type'];
|
|
$annonceCollecte->inter1id = $ann['inter1id'];
|
|
$annonceCollecte->inter1nom = $ann['inter1nom'];
|
|
$annonceCollecte->inter2type = $ann['inter2type'];
|
|
$annonceCollecte->inter2id = $ann['inter2id'];
|
|
$annonceCollecte->inter2nom = $ann['inter2nom'];
|
|
$annonceCollecte->inter3type = $ann['inter3type'];
|
|
$annonceCollecte->inter3id = $ann['inter3id'];
|
|
$annonceCollecte->inter3nom = $ann['inter3nom'];
|
|
$annonceCollecte->complement = $ann['complement'];
|
|
$annonceCollecte->nouvActivite = $ann['nouvActivite'];
|
|
$annonceCollecte->nouvDir = $ann['nouvDir'];
|
|
$annonceCollecte->nouvAdr = $ann['nouvAdr'];
|
|
$annonceCollecte->nouvFJ = $ann['nouvFJ'];
|
|
$annonceCollecte->source = $ann['source'];
|
|
|
|
Metier_Util_Log::write('I',"Lecture de l'annonce collectée n°$idAnn ($siret) : ".$ann['raisonSociale'],__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Edition impossible';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$error->errnum = 745741;
|
|
$error->errmsg = 'Selection impossible';
|
|
}
|
|
}
|
|
$output = new AnnonceCollecteReturn();
|
|
$output->error = $error;
|
|
$output->result = $annonceCollecte;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* getDevises
|
|
* @param string $codeIsoDevise
|
|
* @return DevisesReturn
|
|
*/
|
|
public function getDevises($codeIsoDevise='')
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
if (empty($codeIsoDevise)) $codeIsoDevise = '';
|
|
|
|
Metier_Util_Log::write('I',"Liste des devises ou devise $codeIsoDevise demandée",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabTmp = $iInsee->getDevises($codeIsoDevise);
|
|
|
|
$tabRet = array();
|
|
foreach ($tabTmp as $i=>$dev)
|
|
{
|
|
if ( $i!='' ){
|
|
$devise = new Devise();
|
|
$devise->devIso = $i;
|
|
$devise->devNom = $dev;
|
|
$tabRet[] = $devise;
|
|
}
|
|
}
|
|
$output = new DevisesReturn();
|
|
$output->error = $error;
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Retourne la liste des codes devises, libellés, date et valeur
|
|
* (toutes les devises ou une seule)
|
|
* @param string $devise Devise sur 3 lettres (facultatif)
|
|
* @return DevisesCoursReturn
|
|
*/
|
|
public function getDeviseCours($devise=false)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
|
|
$iDb = new Metier_Util_Db();
|
|
if ($devise) $strDevise=" AND c.devise='$devise' ";
|
|
else $strDevise='';
|
|
|
|
$tabRet = array();
|
|
|
|
$res = $iDb->select('sdv1.devise_cours c, sdv1.devise_liste l', 'c.devise, l.devNom, max(c.date) as dateChange, c.valeur', "c.devise=l.devIso $strDevise GROUP BY c.devise ORDER BY c.devise ASC", false, MYSQL_ASSOC);
|
|
foreach ($res as $tabDev)
|
|
{
|
|
$devise = new DevisesCours();
|
|
$devise->codeDevise = $tabDev['devise'];
|
|
$devise->nomDevise = $tabDev['devNom'];
|
|
$devise->dateChange = $tabDev['dateChange'];
|
|
$devise->valeurDevise = $tabDev['valeur'];
|
|
$tabRet[] = $devise;
|
|
}
|
|
$output = new DevisesCoursReturn();
|
|
$output->error = $error;
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* getMarques
|
|
* @param string $siren
|
|
* @param int $idDepot
|
|
* @return MarquesReturn
|
|
*/
|
|
public function getMarques($siren, $idDepot=0)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('marques');
|
|
Metier_Util_Log::write('I',"Liste des marques déposées pour le siren $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
if (empty($idDepot)) $idDepot = 0;
|
|
$error = new ErrorType();
|
|
$marques = array();
|
|
$iMarque = new Metier_Partenaires_MMarques();
|
|
$ret = $iMarque->getMarques($siren, $idDepot);
|
|
|
|
foreach ($ret as $item)
|
|
{
|
|
if ($idDepot==$item['numeroMarque']) {
|
|
$marque = new Marque();
|
|
$marque->Marques = $item['nomMarque'];
|
|
$marque->Perimetre = $item['periMarque'];
|
|
$marque->Deposant = $item['detailDeposant'];
|
|
$marque->Depot = $item['numeroMarque'];
|
|
$marque->Classes = $item['classesMarque'];
|
|
$marque->ProduitsServices = $item['PS'];
|
|
$marque->Mandataire = $item['detailMandataire'];
|
|
$marque->Statut = $item['detailStatut'];
|
|
$marque->Date = $item['dateDepot'];
|
|
$marque->Lieu = $item['lieuDepot'];
|
|
$marque->Historique = $item['histo'];
|
|
$marque->Img = '';
|
|
$marque->Pdf = $item['pdfLink'];
|
|
|
|
$marques[] = $marque;
|
|
break;
|
|
} else {
|
|
$marque = new Marque();
|
|
$marque->Marques = $item['nomMarque'];
|
|
$marque->Perimetre = '';
|
|
$marque->Deposant = '';
|
|
$marque->Depot = $item['numeroMarque'];
|
|
$marque->Classes = '';
|
|
$marque->Mandataire = '';
|
|
$marque->Statut = '';
|
|
$marque->Date = $item['dateDepot'];
|
|
$marque->Lieu = '';
|
|
$marque->Img = '';
|
|
$marque->Pdf = $item['pdfLink'];
|
|
$marques[] = $marque;
|
|
}
|
|
}
|
|
|
|
$this->wsLog('marques',$siren);
|
|
$output = new MarquesReturn();
|
|
$output->error = $error;
|
|
$output->result = $marques;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Commande de statut association
|
|
* @param InfoCmdAsso $infosCommande
|
|
* @param InfosDemandeur $infosDemandeur
|
|
* @return CmdAssoReturn
|
|
*/
|
|
public function setCmdAsso( $infosCommande, $infosDemandeur )
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('actes');
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
|
|
$iDb = new Metier_Util_Db();
|
|
|
|
$siren = $infosCommande->siren;
|
|
$idEntreprise = intval($infosCommande->idEntreprise);
|
|
$assoNom = $infosCommande->raisonSociale;
|
|
Metier_Util_Log::write('I',"commandeAsso pour $assoNom ($siren) début",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabIdentite = $iInsee->getIdentiteLight($siren, 0, $idEntreprise);
|
|
$assoSigle = $tabIdentite['Sigle'];
|
|
$assoAdresse = $tabIdentite['Adresse'].PHP_EOL.$tabIdentite['Adresse2'];
|
|
$assoCP = $tabIdentite['CP'];
|
|
$assoVille = $tabIdentite['Ville'];
|
|
|
|
$mail = trim($infosDemandeur->email);
|
|
if ($mail=='') $mail = $this->User->email;
|
|
|
|
$dateCommande = date('YmdHis');
|
|
|
|
$tabInsert=array(
|
|
'idUser' => $this->User->id,
|
|
'source' => 'asso',
|
|
'login' => $this->User->login,
|
|
'emailCommande' => $mail,
|
|
'siren' => $siren,
|
|
'refUtilisateur' => $infosDemandeur->reference,
|
|
'refDocument' => serialize($infosDemandeur),
|
|
'refCommande' => serialize($infosCommande),
|
|
'dateCommande' => $dateCommande,
|
|
);
|
|
|
|
$iDbCrm = new Metier_Util_Db();
|
|
$ret = $iDbCrm->insert('sdv1.commandes', $tabInsert, true);
|
|
|
|
if ( $ret!=0 ) {
|
|
$mail = new Metier_Common_Mail();
|
|
$mail->send('production@scores-decisions.com', 'support@scores-decisions.com',
|
|
"Commande de statuts association pour $assoNom ($siren)",
|
|
"Association :".PHP_EOL.print_r($infosCommande, true).PHP_EOL.PHP_EOL.
|
|
"Demandeur:".PHP_EOL.print_r($infosDemandeur, true).PHP_EOL.PHP_EOL.
|
|
"Ref : i".$ret
|
|
);
|
|
$result = new CmdAssoDetail();
|
|
$result->siren = $siren;
|
|
$result->emailCommande = $mail;
|
|
$result->dateCommande = $dateCommande;
|
|
$result->refCmd = 'i'.$ret;
|
|
|
|
$mail->send('production@scores-decisions.com', $mail,
|
|
"Votre commande de statuts association sur $assoNom ($siren)",
|
|
"Votre demande de statuts sur l'association $assoNom a été prise en compte sous la référence i$ret - ".$dateCommande);
|
|
$this->wsLog('commandeAsso', $siren, 'i'.$ret.'-'.$dateCommande);
|
|
Metier_Util_Log::write('I',"commandeAsso pour $assoNom ($siren) fin",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
} else {
|
|
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Erreur';
|
|
|
|
}
|
|
|
|
$output = new CmdAssoReturn();
|
|
$output->error = $error;
|
|
$output->commande = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Commande d'une enquête sur une entreprise en France ou à l'Internationale
|
|
* @param InfosCmdEnquete $infosCommande
|
|
* @param InfosDemandeur $infosDemandeur
|
|
* @return CmdEnqueteReturn
|
|
**/
|
|
public function setCmdEnquete($infosCommande, $infosDemandeur)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('enquetec');
|
|
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
$siren = $infosCommande->siren;
|
|
|
|
$mail = trim($infosDemandeur->email);
|
|
if ($mail=='') $mail = $this->User->email;
|
|
|
|
$dateCommande = date('YmdHis');
|
|
|
|
$tabInsert = array(
|
|
'idUser' => $this->User->id,
|
|
'source'=> 'intersud', // 'greffes', 'asso', 'graydon'
|
|
'login'=> $this->User->login,
|
|
'emailCommande'=> $mail,
|
|
'siren'=> $siren,
|
|
'refDocument'=> serialize($infosDemandeur),
|
|
'refCommande'=> serialize($infosCommande),
|
|
'dateCommande'=> $dateCommande,
|
|
);
|
|
Metier_Util_Log::write('I',"Intersud, début sur $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$messageInfo=print_r($infosCommande, 1).PHP_EOL.print_r($infosDemandeur,1).PHP_EOL;
|
|
|
|
$idClient = $this->User->idClient;
|
|
$iDbCrm = new Metier_Util_Db();
|
|
$rep = $iDbCrm->select('sdv1.clients', ' nom, racineLogin, InterSudLogin, InterSudPass', "id='$idClient'", false, MYSQL_ASSOC);
|
|
$login = trim($rep[0]['InterSudLogin']);
|
|
$pass = trim($rep[0]['InterSudPass']);
|
|
$nomClient = trim(strtoupper($rep[0]['nom']));
|
|
$strInfoCommande ="NOM et Prénom du client demandeur : ".$infoDemandeur->nom.PHP_EOL;
|
|
$strInfoCommande.="Email du client demandeur : $mail".PHP_EOL;
|
|
$strInfoCommande.="Tel/Fax du demandeur : ".$infosDemandeur->tel.' / '.$infosDemandeur->fax.PHP_EOL;
|
|
$strInfoCommande.="Profil du demandeur : ".trim($infosDemandeur->service).PHP_EOL;
|
|
$typeEnqLog='enqueteDemNF';
|
|
|
|
if ($login=='' || $pass=='') {
|
|
/** Il ne s'agit pas d'un client final, on anonymise la commande **/
|
|
$login = 'YLENA'; // Demandes en test
|
|
$pass = 'WYLFE';
|
|
$nomClient = $strInfoCommande = '';
|
|
$typeEnqLog = 'enqueteDem';
|
|
/* ENQUETES EN PROD
|
|
$login='FACTURE';
|
|
$pass='AWKROM';
|
|
*/
|
|
}
|
|
|
|
$url='http://www.intersud.fr/espace_client/espace_client.php';
|
|
$cookie = $referer = '';
|
|
$tabPost = array('login' => $login, 'pwd' => $pass);
|
|
$tdeb = microtime(true);
|
|
$page = getUrl($url, $cookie, $tabPost, $referer, false, '', '', 7);
|
|
if ($page['code']<>200) {
|
|
$tabRet=array();
|
|
//@todo
|
|
return array('error'=>array('errnum'=>4563456, 'errmsg'=>'Connexion impossible à la plateforme d\'enquetes'), 'results'=>$tabRet);
|
|
}
|
|
$tfin = microtime(true);
|
|
$duree = $tfin-$tdeb;
|
|
$referer = $url;
|
|
$body = $page['body'];
|
|
$cookie = $page['header']['Set-Cookie'];
|
|
|
|
/** Connexion à l'Extranet Intersud
|
|
**/
|
|
$url = 'http://intersud.fr/espace_client/demande_enquete.php';
|
|
$tdeb = microtime(true);
|
|
$page = getUrl($url, $cookie, '', $referer, false, '', '', 7);
|
|
$tfin = microtime(true);
|
|
$duree+= $tfin-$tdeb;
|
|
$referer = $url;
|
|
$body = $page['body'];
|
|
|
|
$fp=fopen(LOG_PATH."/intersud.log", "a");
|
|
fwrite($fp, print_r($page,true));
|
|
fclose($fp);
|
|
$tabInterSud=array();
|
|
if (preg_match_all('/<input(?:.*)name="(.*)"(?:.*)value="(.*)"/Uim',$body,$matches)) {
|
|
foreach ($matches[1] as $i=>$field) {
|
|
$tmp=explode('"', $matches[2][$i]);
|
|
$tabInterSud[$field]=$tmp[0];
|
|
}
|
|
}
|
|
if (preg_match_all('/<input(?:.*)value="(.*)"(?:.*)name="(.*)"/Uim',$body,$matches)) {
|
|
foreach ($matches[2] as $i=>$field) {
|
|
$tmp=explode('"', $matches[1][$i]);
|
|
$tabInterSud[$field]=$tmp[0];
|
|
}
|
|
}
|
|
|
|
$ref_exp=$tabInterSud['ref_exp'];
|
|
$email_exp=$tabInterSud['email_exp'];
|
|
$tel_exp=$tabInterSud['tel_exp'];
|
|
Metier_Util_Log::write('I',"Intersud, formulaire enquête ref $ref_exp, $email_exp, $tel_exp",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$fp=fopen(LOG_PATH."/intersud.log", "a");
|
|
fwrite($fp, print_r($matches,true));
|
|
fwrite($fp, print_r($tabInterSud,true));
|
|
fclose($fp);
|
|
|
|
/** Insertion de la commande en base
|
|
**/
|
|
$ret = $iDbCrm->insert('sdv1.commandes', $tabInsert, true);
|
|
$comment = "Référence de la commande chez Scores et Décisions : i$ret - ".
|
|
$dateCommande."\n".
|
|
"Date et heure de la commande : ".date('d/m/Y - H:i')."\n".
|
|
"Origine de la commande : $nomClient".
|
|
"$strInfoCommande"."\n\n".
|
|
|
|
"CA : ".$infosCommande->PrecisionsMontantCA."\n".
|
|
"Motif de la demande : ".trim($infosCommande->PrecisionsMotif.' '.$infosCommande->PrecisionsAutre)."\n".
|
|
"Type de la demande : ".$infosCommande->PrecisionsType."\n".
|
|
"Anciennete de la relation : ".$infosCommande->Anciennete.' '.$infosCommande->AncienneteDuree."\n".
|
|
"Observations : ".$infosCommande->Observation.PHP_EOL;
|
|
|
|
if ($infosCommande->ImpayeesChoix<>'non')
|
|
$comment.="Impayé(s) : ".$infosCommande->ImpayeesNombre." impayé(s) pour un montant de ".$infosCommande->ImpayeesMontant." en date du ".$infosCommande->ImpayeesDate.PHP_EOL;
|
|
|
|
if ($infosCommande->RetardPaiementChoix<>'non')
|
|
$comment.="Retard(s) de paiement : ".$infosCommande->RetardPaiementNombre." retard(s) pour un montant de ".$infosCommande->RetardPaiementMontant." en date du ".$infosCommande->RetardPaiementDate.PHP_EOL;
|
|
|
|
if ($infosCommande->LitigeChoix<>'non')
|
|
$comment.="Présence de litige(s) : ".$infosCommande->LitigePrecisions.PHP_EOL;
|
|
|
|
$enqType=0;
|
|
$enqDelai=7;
|
|
switch (strtolower($infosCommande->Type)) {
|
|
case 'premier': $enqType=0; $enqDelai=6; break;
|
|
case 'gold': $enqType=1; break;
|
|
case 'distrimat': $enqType=2; break;
|
|
case 'star': $enqType=3; break;
|
|
case 'avis_bancaire': $enqType=4; break;
|
|
case 'autre': $enqType=5; break;
|
|
}
|
|
|
|
/** Ajout du RIB si communiqué **/
|
|
if (@trim(implode(' ', $infosCommande->RIB))<>'')
|
|
$iDbCrm->insert('sdv1.banques', array(
|
|
'siren'=>$siren,
|
|
'libBanqueGuichet'=>'',
|
|
'precis'=>1,
|
|
'codeBanque'=>$infosCommande->RIB->banque,
|
|
'codeGuichet'=>$infosCommande->RIB->guichet,
|
|
'numCompte'=>$infosCommande->RIB->compte.$infosCommande->RIB->cle,
|
|
'dateSource'=>$dateCommande,
|
|
), true);
|
|
|
|
/** Remplissage du formulaire d'enquête pour soumission à Intersud **/
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabIdentite = $iInsee->getIdentiteLight($siren);
|
|
$tabPost = array(
|
|
'soc'=>$tabIdentite['Nom'],
|
|
'cible_enk'=>9, // 9
|
|
'siret'=>$siren,
|
|
'acti'=>'',
|
|
'soc_exp'=>$tabInterSud['soc_exp'],
|
|
'type_enk'=>$enqType, // 0=Premier, 1=Gold, 2=Distrimat, 3=Star, 4=Avis bancaire, 5=Autre
|
|
'nom_diri'=>'',
|
|
'adr'=>$tabIdentite['Adresse'],
|
|
'ref_exp'=>$tabInterSud['ref_exp'],
|
|
'autre_type_enk'=>'', // Texte libre
|
|
'adr2'=>$tabIdentite['Adresse2'],
|
|
'delai_enk'=>$enqDelai, // 6=24h, 7=72h, 8=+de5jours
|
|
'ville'=>$tabIdentite['Ville'],
|
|
'cp'=>$tabIdentite['CP'],
|
|
'pays'=>'', // International ?
|
|
'nom_exp'=>$tabInterSud['nom_exp'],
|
|
'tel'=>$tabIdentite['Tel'],
|
|
'port'=>$infosCommande->AutreTel,
|
|
'tel_exp'=>$tabInterSud['tel_exp'],
|
|
'bank'=>trim(implode(' ', $infosCommande->RIB)),
|
|
'int_enk'=>$tabInterSud['int_enk'], // International ?
|
|
'encours'=>$infosCommande->Encours,
|
|
'nb_ech'=>$infosCommande->NbEcheances,
|
|
'delai2_enk'=>$tabInterSud['delai2_enk'], // International ?
|
|
'email_exp'=>$tabInterSud['email_exp'],
|
|
'cred'=>'',
|
|
'comment'=>urlencode($comment),
|
|
'val_ret'=>$tabInterSud['val_ret'],
|
|
);
|
|
$url='http://intersud.fr/espace_client/demande_enquete.php';
|
|
$tdeb=microtime(true);
|
|
$page=getUrl($url, $cookie, $tabPost, $referer, false, '', '', 7);
|
|
if ($page['code']<>200) {
|
|
$tabRet=array();
|
|
return array('error'=>array('errnum'=>456345, 'errmsg'=>'Connexion impossible à la plateforme d\'enquetes 3'), 'results'=>$tabRet);
|
|
}
|
|
$tfin=microtime(true);
|
|
$duree+=$tfin-$tdeb;
|
|
$referer=$url;
|
|
$body=$page['body'];
|
|
|
|
$result = new CmdEnquete();
|
|
$result->siren = $siren;
|
|
$result->emailCommande = $mail;
|
|
$result->dateCommande = $dateCommande;
|
|
$result->refCmd = 'i'.$ret;
|
|
|
|
$mail = new Metier_Common_Mail();
|
|
$mail->send('production@scores-decisions.com', 'support@scores-decisions.com', "Commande d'enquete sur $siren", $comment.PHP_EOL.PHP_EOL.'---------------------------------'.PHP_EOL.$messageInfo.PHP_EOL.PHP_EOL.'---------------------------------'.PHP_EOL.$body);
|
|
$this->wsLog($typeEnqLog, $siren, 'i'.$ret.'-'.$dateCommande);
|
|
|
|
/** Gestion de la déconnexion **/
|
|
$url='http://intersud.fr/espace_client/index.php?code_ret=9';
|
|
$tdeb=microtime(true);
|
|
$page=getUrl($url, $cookie, '', $referer, false, '', '', 7);
|
|
$tfin=microtime(true);
|
|
$duree+=$tfin-$tdeb;
|
|
|
|
$ret = $iDbCrm->update('sdv1.commandes', array('dureeCommande'=>round($duree,3)), "idCommande=$ret");
|
|
|
|
$output = new CmdEnqueteReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* getStatsUtilisateurs
|
|
* @param string $login
|
|
* @param string $mois
|
|
* @param string $type
|
|
* @param boolean $payants
|
|
* @return array
|
|
*/
|
|
public function getStatsUtilisateurs($login, $mois, $type='jour', $payants=false)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
if ($payants)
|
|
{
|
|
$strPayant="AND (page LIKE 'greffe_%' OR page LIKE 'inpi_%' OR page='kbis') AND params<>'' AND (params NOT LIKE '%erreur%' OR params LIKE '%erreur 17%') ";
|
|
}
|
|
else {
|
|
$strPayant='';
|
|
}
|
|
$iDbCrm = new Metier_Util_Db();
|
|
if ($type=='jour') {
|
|
$rep = $iDbCrm->select('sdv1.logs',
|
|
'date(dateHeure) as jours, count(*) as nb',
|
|
"1 $strPayant AND login='$login' AND dateHeure BETWEEN '$mois-01' AND '$mois-31' GROUP BY jours",
|
|
false, MYSQL_ASSOC);
|
|
} elseif ($type=='heure') {
|
|
$rep = $iDbCrm->select('sdv1.logs',
|
|
'HOUR(dateHeure) as heures, count(*) as nb',
|
|
"1 $strPayant AND login='$login' AND dateHeure BETWEEN '$mois-01' AND '$mois-31' GROUP BY heures",
|
|
false, MYSQL_ASSOC);
|
|
}
|
|
$tabRet = $rep;
|
|
|
|
|
|
|
|
return array('error'=>array('errnum'=>0, 'errmsg'=>''), 'results'=>$tabRet);
|
|
}
|
|
|
|
/**
|
|
* getPortefeuilleCsv
|
|
* @param string $login
|
|
* @param int $idClient
|
|
* @return ListeSurveillancesCsvReturn
|
|
*/
|
|
public function getPortefeuilleCsv($login='', $idClient=0)
|
|
{
|
|
return $this->getListeSurveillancesCsv('portefeuille', $login, $idClient);
|
|
}
|
|
|
|
/**
|
|
* getPortefeuille
|
|
* @param PortefeuilleFiltre $filtre
|
|
* @param int $deb
|
|
* @param int $nbRet
|
|
* @return PortefeuilleReturn
|
|
*/
|
|
public function getPortefeuille($filtre, $deb=0, $nbRet=100)
|
|
{
|
|
$this->authenticate();
|
|
|
|
// Initialisation
|
|
$error = new ErrorType();
|
|
if (empty($deb)) { $deb = 0; }
|
|
if (empty($nbRet)) { $nbRet = 100; }
|
|
|
|
$tri = strtolower(trim($filtre->tri));
|
|
switch ($tri) {
|
|
case 'ref': $orderBy='ORDER BY ref'; break;
|
|
case 'dateAjout': $orderBy='ORDER BY dateAjout'; break;
|
|
case 'dateDerEnvoi':$orderBy='ORDER BY dateDerEnvoi'; break;
|
|
case 'rs': $orderBy='ORDER BY rs'; break;
|
|
case 'cp': $orderBy='ORDER BY cp'; break;
|
|
case 'ville': $orderBy='ORDER BY ville'; break;
|
|
case 'indiScore': $orderBy='ORDER BY indiScore'; break;
|
|
case 'encours': $orderBy='ORDER BY encours'; break;
|
|
default: $orderBy='ORDER BY siren'; break; // siren ou vide ou autre
|
|
}
|
|
|
|
$tabRet = array();
|
|
$siren = substr($filtre->siret,0,9);
|
|
$nic = substr($filtre->siret,9,5);
|
|
$iDb = new Metier_Util_Db();
|
|
$login = $this->User->login;
|
|
|
|
$strSelect = 's.email, LPAD(s.siren,9,0) AS siren, LPAD(s.nic,5,0) AS nic, s.ref, s.dateAjout, s.rs, s.cp, s.ville, s.dateDerEnvoi, s.encoursClient, c.actif, c.procol, c.indiScore, c.indiScore20, c.encours, c.indiScoreDate, c.dateBilan, c.indiScorePre, c.indiScore20Pre, c.encoursPre, c.indiScoreDatePre, c.sourceModif, c.scoreSolv, c.scoreSolvPre, c.scoreDir, c.scoreDirPre, c.scoreConf, c.scoreConfPre, c.scoreZ, c.scoreZPre, c.scoreCH, c.scoreCHPre, c.scoreAfdcc2, c.scoreAfdcc2Pre, c.situFi, c.situFiPre, c.infoNote, c.infoNotePre, c.noteStruct, c.noteStructPre, c.noteFin, c.noteFinPre, c.tendance, c.tendancePre, c.dateUpdate';
|
|
|
|
$strFiltre = '';
|
|
if (intval($siren)>0) $strFiltre.= " AND s.siren=$siren ";
|
|
if (!empty($filtre->ref)) $strFiltre.= " AND s.ref LIKE '%$filtre->ref%'";
|
|
if (!empty($filtre->rs)) $strFiltre.= " AND s.rs LIKE '%$filtre->rs%'";
|
|
|
|
// Il faut compter le nombre de siren au total
|
|
$tabTmp = $iDb->select('jo.surveillances_site s', 'count(*) as nb', "s.login='$login' AND s.source='score' AND s.dateSuppr=0 $strFiltre", false, MYSQL_ASSOC);
|
|
$nbRepTot = $tabTmp[0]['nb'];
|
|
|
|
$tabTmp = $iDb->select('jo.surveillances_site s, jo.scores_surveillance c', $strSelect, "s.login='$login' AND s.source='score' AND s.dateSuppr=0 AND s.siren=c.siren $strFiltre $orderBy LIMIT $deb,$nbRet", false, MYSQL_ASSOC);
|
|
foreach ($tabTmp as $i=>$tabSurv) {
|
|
if (trim($tabSurv['rs'])<>'') {
|
|
$rs=$tabSurv['rs'];
|
|
$cp=$tabSurv['cp'];
|
|
$ville=$tabSurv['ville'];
|
|
} else {
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabIdentite = $iInsee->getIdentiteLight($tabSurv['siren'], $tabSurv['nic']);
|
|
$rs=$tabIdentite['Nom'];
|
|
$cp=$tabIdentite['CP'];
|
|
$ville=$tabIdentite['Ville'];
|
|
$iDb->update('jo.surveillances_site',array(
|
|
'rs' => $rs,
|
|
'cp' => $cp,
|
|
'ville' => $ville),
|
|
"login='$login' AND source='score' AND dateSuppr=0 AND siren=".$tabSurv['siren']." AND nic=".$tabSurv['nic'],
|
|
false
|
|
);
|
|
}
|
|
|
|
$portefeuille = new Portefeuille();
|
|
$portefeuille->email = $tabSurv['email'];
|
|
$portefeuille->siren = $tabSurv['siren'];
|
|
$portefeuille->nic = $tabSurv['nic'];
|
|
$portefeuille->ref = $tabSurv['ref'];
|
|
$portefeuille->dateAjout = $tabSurv['dateAjout'];
|
|
$portefeuille->rs = $rs;
|
|
$portefeuille->cp = $cp;
|
|
$portefeuille->ville = $ville;
|
|
// Entreprise
|
|
$portefeuille->actif = $tabSurv['actif'];
|
|
$portefeuille->procol = $tabSurv['procol'];
|
|
$portefeuille->indiScore = $tabSurv['indiScore'];
|
|
$portefeuille->indiScore20 = $tabSurv['indiScore20'];
|
|
$portefeuille->indiScorePre = $tabSurv['indiScorePre'];
|
|
$portefeuille->indiScore20Pre = $tabSurv['indiScore20Pre'];
|
|
$portefeuille->encours = $tabSurv['encours'];
|
|
$portefeuille->encoursPre = $tabSurv['encoursPre'];
|
|
$portefeuille->indiScoreDate = $tabSurv['indiScoreDate'];
|
|
$portefeuille->indiScoreDatePre = $tabSurv['indiScoreDatePre'];
|
|
$portefeuille->encoursClient = $tabSurv['encoursClient'];
|
|
$portefeuille->dateBilan = $tabSurv['dateBilan'];
|
|
$portefeuille->sourceModif = $tabSurv['sourceModif'];
|
|
//, c.scoreSolv, c.scoreSolvPre, c.scoreDir, c.scoreDirPre, c.scoreConf, c.scoreConfPre, c.scoreZ, c.scoreZPre, c.scoreCH, c.scoreCHPre, c.scoreAfdcc2, c.scoreAfdcc2Pre, c.situFi, c.situFiPre, c.infoNote, c.infoNotePre, c.noteStruct, c.noteStructPre, c.noteFin, c.noteFinPre, c.tendance, c.tendancePre, c.dateUpdate';
|
|
$portefeuille->dateDerEnvoi = $tabSurv['dateDerEnvoi'];
|
|
$tabRet[] = $portefeuille;
|
|
|
|
}
|
|
|
|
$output = new PortefeuilleReturn();
|
|
$output->error = $error;
|
|
$output->result = $tabRet;
|
|
$output->nbReponses = count($tabRet);
|
|
$output->nbReponsesTotal = $nbRepTot;
|
|
return $output;
|
|
}
|
|
|
|
|
|
/**
|
|
* rechercheHisto
|
|
* @param string $recherche
|
|
* @param string $annee
|
|
* @param string $typeBod
|
|
* @param int $deb
|
|
* @param int $nbRep
|
|
* @param int $maxRep
|
|
* @param bool $pertinence
|
|
* @return RechercheHistoReturn
|
|
*/
|
|
public function rechercheHisto($recherche, $annee='', $typeBod='', $deb=0, $nbRep=20, $maxRep=200, $pertinence=false)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
if (empty($annee)) $annee = '';
|
|
if (empty($typeBod)) $typeBod = '';
|
|
if (empty($deb)) $deb = 0;
|
|
if (empty($nbRep)) $nbRep = 20;
|
|
if (empty($maxRep)) $maxRep = 200;
|
|
if (empty($annee)) $pertinence = false;
|
|
$liste = array();
|
|
$index = 'histo';
|
|
|
|
Metier_Util_Log::write('I',"rechercheHisto de $recherche ($annee) (Max Rep=$nbRep)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$tabFiltres = array();
|
|
|
|
if ($annee<>'' && $annee*1>=1953 && $annee*1<=date('Y')*1)
|
|
$tabFiltres = array('annee1'=>$annee);
|
|
|
|
if (SPHINX_HISTO_VERSION == 1){
|
|
require_once 'SphinxSearch/sphinxapi-0.9.9.php';
|
|
} elseif (SPHINX_HISTO_VERSION == 2){
|
|
require_once 'SphinxSearch/sphinxapi-2.2.9.php';
|
|
}
|
|
|
|
$cl = new SphinxClient();
|
|
$cl->SetServer (SPHINX_HISTO_HOST, SPHINX_HISTO_PORT);
|
|
$cl->SetConnectTimeout(1);
|
|
$cl->SetLimits ($deb, $nbRep, $maxRep);
|
|
$cl->SetMatchMode (SPH_MATCH_EXTENDED);
|
|
foreach ($tabFiltres as $nomFiltre => $valFiltre)
|
|
$cl->SetFilter($nomFiltre, array(0=>$valFiltre));
|
|
$cl->SetRankingMode (SPH_RANK_PROXIMITY_BM25);
|
|
$res = $cl->Query ($recherche, $index);
|
|
|
|
if ($res===false) {
|
|
Metier_Util_Log::write('I',"Search Sphinx : Pas de réponse pour $recherche avec ".implode(',',$tabFiltres).' ('.$cl->GetLastError() .')',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$criteres = new RechercheHistoCriteres();
|
|
$criteres->recherche = $recherche;
|
|
$criteres->annee = $annee;
|
|
|
|
$output = new RechercheHistoReturn();
|
|
$output->criteres = $criteres;
|
|
$output->nbReponses = 0;
|
|
$output->nbReponsesTotal = 0;
|
|
$output->duree = $res[time];
|
|
$output->mots = array();
|
|
$output->reponses = array();
|
|
return $output;
|
|
|
|
}
|
|
// Le moteur est opérationel
|
|
if ( $cl->GetLastWarning() ) {
|
|
Metier_Util_Log::write('I',"Search Sphinx : Warning pour $recherche - ".$cl->GetLastWarning(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
//print "WARNING: " . $cl->GetLastWarning() . "\n\n";
|
|
}
|
|
|
|
Metier_Util_Log::write('I',"'Search Sphinx dans $index de $recherche (Filtre=".implode(',',$tabFiltres)."), Deb=$deb, nbRep=$nbRep, max=$max, any=$any",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$tabRet=array();
|
|
if ( is_array($res['matches'])) {
|
|
$iDb = new Metier_Util_Db();
|
|
foreach ( $res['matches'] as $doc => $docinfo )
|
|
{
|
|
$listeEtab=$iDb->select('histobodacc.bodacc_ocr',
|
|
"'Histo' as Loc, id, nomFichier, annee1, bod, texte",
|
|
"id=$doc");
|
|
$etab = $listeEtab[0];
|
|
$tabRet[]=array(
|
|
'Localisation' => $etab['Loc'],
|
|
'id' => $doc,
|
|
'Pertinence' => $docinfo['weight'],
|
|
'Fichier' => $etab['nomFichier'],
|
|
'Annee' => $etab['annee1'],
|
|
'Code' => $etab['bod'],
|
|
'Texte' => $etab['texte'],
|
|
);
|
|
}
|
|
}
|
|
Metier_Util_Log::write('I','Search Sphinx : Retourne '. $res[total].'/'. $res[total_found] .' en '.$res[time] .'secondes',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$liste = $tabRet;
|
|
$nbTot = $res[total_found];
|
|
$duree = $res[time];
|
|
$tabMots = $res['words'];
|
|
|
|
$tabRet = array();
|
|
$k=0;
|
|
if(count($liste)>0) {
|
|
foreach ($liste as $n=>$etab) {
|
|
$texte = Scores_Locale_String::cleanutf8($etab['Texte']);
|
|
$pattern = '/[^a-zA-Z0-9\/]+/ ';
|
|
$texte = preg_replace($pattern, ' ', $texte);
|
|
$posMin=100000;
|
|
$hitMin=1000000;
|
|
foreach ($tabMots as $mot=>$tabMot) {
|
|
if ($tabMot['hits']<$hitMin) {
|
|
$hitMin=$tabMot['hits'];
|
|
$motSignificatif=$mot;
|
|
}
|
|
}
|
|
$posMin = stripos($texte, ''.$motSignificatif);
|
|
if ($posMin<150) $posMin=150;
|
|
$texte2 = substr($texte, $posMin-150, 250);
|
|
$reponse = new RechercheHistoReponses();
|
|
$reponse->id = $etab['id'];
|
|
$reponse->Pertinence = $etab['Pertinence'];
|
|
|
|
//@todo : gestion du lien pour le téléchargement des fichiers bodacc
|
|
$file = strtr($etab['Fichier'], array(
|
|
'.txt'=>'.pdf',
|
|
'/mnt/bodacc/' => ''));
|
|
$vieuxWS = false;
|
|
if ($vieuxWS) {
|
|
$reponse->Fichier = 'http://tville.scores-decisions.com/bodacc/'.$file;
|
|
} else {
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
if ($_SERVER['SERVER_PORT']!='80'){
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
}
|
|
$url = '/fichier/bodacc/q/'.base64_encode($file);
|
|
$reponse->Fichier = $hostname.$url;
|
|
}
|
|
$reponse->Annee = $etab['Annee'];
|
|
$reponse->Code = $etab['Code'];
|
|
$reponse->Texte = $texte2;
|
|
$tabRet[] = $reponse;
|
|
$k++;
|
|
}
|
|
}
|
|
|
|
$criteres = new RechercheHistoCriteres();
|
|
$criteres->recherche = $recherche;
|
|
$criteres->annee = $annee;
|
|
|
|
$output = new RechercheHistoReturn();
|
|
$output->criteres = $criteres;
|
|
$output->nbReponses = count($tabRet);
|
|
$output->nbReponsesTotal = $nbTot;
|
|
$output->duree = $duree;
|
|
$output->mots = array_keys($tabMots);
|
|
$output->reponses = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* getListeSurveillanceCsv
|
|
* @param string $source
|
|
* @param string $login
|
|
* @param int $idClient
|
|
* @return ListeSurveillancesCsvReturn
|
|
*/
|
|
public function getListeSurveillancesCsv($source='', $login='', $idClient=0)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
if (empty($source)) $source = '';
|
|
if (empty($idClient)) $idClient = 0;
|
|
|
|
Metier_Util_Log::write('I',"getListeSurveillancesCsv Début $source $login $idClient",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$tabRet = array();
|
|
$iDb = new Metier_Util_Db();
|
|
$strClient = $strLogin = '';
|
|
$exportPtf = false;
|
|
switch ($source)
|
|
{
|
|
case 'insee':
|
|
case 'annonces':
|
|
case 'bilans':
|
|
case 'score':
|
|
case 'actes':
|
|
case 'privileges':
|
|
case 'dirigeants':
|
|
break;
|
|
case 'portefeuille':
|
|
$source='score';
|
|
$exportPtf=true;
|
|
break;
|
|
default:
|
|
$source='';
|
|
break;
|
|
}
|
|
|
|
if ($source<>'') $strSource = "AND source='$source' ";
|
|
else $strSource = '';
|
|
|
|
// Control idClient
|
|
if ($idClient==0 || ($idClient!=$this->User->idClient && $this->User->profil!='SuperAdministrateur') ){
|
|
$idClient = $this->User->idClient;
|
|
}
|
|
$strClient = "AND u.idClient=$idClient ";
|
|
|
|
if ($this->User->profil=='SuperAdministrateur' || $this->User->profil=='Administrateur') {
|
|
// Surveillances de tous les utilisateurs du client
|
|
if (empty($login)) {
|
|
$login = '';
|
|
}
|
|
//Surveillances de l'utilisateur
|
|
else {
|
|
$strLogin = "AND s.login='$login' ";
|
|
}
|
|
} else {
|
|
//Par défaut préselection de l'utilisateur
|
|
$login = $this->User->login;
|
|
$strLogin = "AND s.login='$login' ";
|
|
}
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$path = $c->profil->path->shared.'/files';
|
|
$fichierCsv = $path."/listesurv-$source-$login-$idClient.csv";
|
|
|
|
if ( file_exists($fichierCsv)
|
|
&& date('Ymd', filemtime($fichierCsv))==date('Ymd')
|
|
&& filesize($fichierCsv)>60 ) {
|
|
$size = filesize($fichierCsv);
|
|
$erreur = false;
|
|
$tabNom = array();
|
|
$cache = 1;
|
|
} else {
|
|
unlink($fichierCsv);
|
|
if ($source=='score') {
|
|
if ($this->User->typeScore==20) {
|
|
$strScore='v.indiScore20 AS indiScore20';
|
|
$strScorePre='v.indiScore20Pre AS indiScore20Pre';
|
|
} else {
|
|
$strScore='v.indiScore AS indiScore100';
|
|
$strScorePre='v.indiScorePre AS indiScore100Pre';
|
|
}
|
|
$sql="SELECT LOWER(s.login) as loginUti, s.source, s.email, s.siren, s.nic, s.ref, s.dateAjout,
|
|
s.rs, s.cp, s.ville, s.dateDerEnvoi,
|
|
s.encoursClient, v.actif, v.procol, $strScore, v.encours, v.indiScoreDate, v.dateBilan,
|
|
$strScorePre, v.encoursPre, v.indiScoreDatePre, v.sourceModif, v.scoreSolv, v.scoreSolvPre, v.scoreDir,
|
|
v.scoreDirPre, v.scoreConf, v.scoreConfPre,
|
|
e.cj, e.capital, e.capitalDev, e.ape_entrep, e.tca, e.teff_entrep,
|
|
v.dateUpdate
|
|
FROM jo.surveillances_site s, sdv1.utilisateurs u, sdv1.clients c, jo.scores_surveillance v, jo.etablissements e
|
|
WHERE s.source='score' $strClient $strLogin AND dateSuppr=0 AND s.login=u.login AND u.idClient=c.id AND s.siren=v.siren AND s.siren=e.siren
|
|
GROUP BY loginUti, s.siren, s.nic, s.source, s.ref
|
|
ORDER BY loginUti ASC, s.siren ASC, s.nic ASC, s.source ASC, s.ref ASC";
|
|
}
|
|
else {
|
|
$sql="SELECT LOWER(s.login) as loginUti, s.source, s.email, s.siren, s.nic, s.ref, s.dateAjout,
|
|
s.rs, s.cp, s.ville, s.dateDerEnvoi
|
|
FROM jo.surveillances_site s, sdv1.utilisateurs u, sdv1.clients c
|
|
WHERE 1 $strSource $strClient $strLogin AND dateSuppr=0 AND s.login=u.login AND u.idClient=c.id
|
|
ORDER BY loginUti ASC, s.siren ASC, s.nic ASC, s.source ASC, s.ref ASC";
|
|
}
|
|
Metier_Util_Log::write('I',"getListeSurveillancesCsv SQL $sql",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$c = Zend_Registry::get('config');
|
|
$path = $c->profil->path->shared.'/files';
|
|
file_put_contents($path."/listesurv-$source-$login-$idClient.sql", $sql);
|
|
exec("php ".APPLICATION_PATH."/../scripts/jobs/sql2csv.php --sqlfile ".$path."/listesurv-$source-$login-$idClient.sql --csvfile $fichierCsv > /dev/null &");
|
|
$size=$cache=0;
|
|
}
|
|
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
if ($_SERVER['SERVER_PORT']!='80'){
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
}
|
|
$result = new ListeSurveillancesCsv();
|
|
$result->Url = $hostname."/fichier/csv/listesurv-$source-$login-$idClient.csv";
|
|
$result->Taille = $size;
|
|
$result->Cache = $cache;
|
|
|
|
Metier_Util_Log::write('I','getListeSurveillancesCsv Url='.$hostname."/fichier/csv/listesurv-$source-$login-$idClient.csv, Taille=$size, Cache=$cache",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$output = new ListeSurveillancesCsvReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* getListeJalCollecte
|
|
* @return ListeJalCollecteReturn
|
|
*/
|
|
public function getListeJalCollecte()
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
|
|
$iBodacc = new Metier_Bodacc_MBodacc();
|
|
$tabJal = $iBodacc->getListeJalCollecte();
|
|
foreach ($tabJal as $i=>$jal)
|
|
{
|
|
$jalCollecte = new JalCollecte();
|
|
$jalCollecte->id = $i;
|
|
$jalCollecte->nom = $jal;
|
|
$tabRet[] = $jalCollecte;
|
|
}
|
|
$output = new ListeJalCollecteReturn();
|
|
$output->error = $error;
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* getListeFichierSurv
|
|
* @param string $login
|
|
* @param string $ref
|
|
* @param string $nomFic
|
|
* @return ListeFichierSurvReturn
|
|
*/
|
|
public function getListeFichierSurv($login, $ref='*', $nomFic='')
|
|
{
|
|
$this->authenticate();
|
|
$c = Zend_Registry::get('config');
|
|
$path = $c->profil->path->shared."/clients/oldcrm";
|
|
|
|
if (empty($ref)) $ref = '*';
|
|
if (empty($nomFic)) $nomFic = '';
|
|
$error = new ErrorType();
|
|
$tabFichier = $tabDates = array();
|
|
$numAbo = substr($ref, 0,5);
|
|
if (strtolower($login)=='vwbank') {
|
|
$ficClient='surveillanceBodacc_SURBODPRDCFTVWBANK';
|
|
$numAbo = $ref = '19300';
|
|
} elseif (substr($login,0,6)=='apicil') {
|
|
$ficClient='surveillanceBodacc_SURBODPRDCFTAPICIL';
|
|
$numAbo = $ref = '';
|
|
} elseif (strtolower($login)=='omni04') {
|
|
$ficClient='surveillanceBodacc_SURBODPRDFTSOMNIREP';
|
|
$numAbo = $ref = '';
|
|
} elseif (strtolower($login)=='bodacca3m' /*|| strtolower($login)=='mricois'*/) {
|
|
$ficClient='surveillanceBodacc_SURBODPRDFTSMEDERIC';
|
|
$numAbo = $ref = '';
|
|
} elseif (strtolower($login)=='bodaccomni') {
|
|
$ficClient='surveillanceBodacc_SURBODPRDFTSOMNIREP';
|
|
$numAbo = $ref = '';
|
|
} elseif (strtolower($login)=='bodacccrr') {
|
|
$ficClient='surveillanceBodacc_SURBODPRDFTSCRR';
|
|
$numAbo = $ref = '';
|
|
} elseif (strtolower($login)=='cpcambr13' || strtolower($login)=='cpcambr14' /*|| strtolower($login)=='mricois'*/) {
|
|
$ficClient='diffusionBodacc_DIFBODPRDMAICPCAM13';
|
|
$numAbo = $ref = '';
|
|
} elseif (strtolower($login)=='frbsurveillance'){
|
|
$ficClient='surveillanceBodacc_SURBODPRDFTPFBOISSON';
|
|
$numAbo = $ref = '';
|
|
} else {
|
|
$ficClient='surveillanceBodacc_SURBODTSTFTSCNASEA';
|
|
$numAbo = $ref = '';
|
|
}
|
|
|
|
// --- Livraison fichier
|
|
if ($nomFic!='') {
|
|
$directory = $c->profil->path->shared.'/files';
|
|
$ficLength = strlen($ficClient . $numAbo);
|
|
if (file_exists($path.'/'.$nomFic) && substr($nomFic, 0, $ficLength) == $ficClient . $numAbo) {
|
|
if (!file_exists($directory."/$nomFic.bz2") || filesize($directory."/$nomFic.bz2") <= 14) {
|
|
$string = file_get_contents($path."/$nomFic");
|
|
$bz = bzopen($directory."/$nomFic.bz2",'w');
|
|
if ($bz) {
|
|
bzwrite($bz, $string, strlen($string));
|
|
bzclose($bz);
|
|
}
|
|
}
|
|
$tabFichier[] = $nomFic;
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = "Impossible d'ouvrir le fichier client";
|
|
}
|
|
} else {
|
|
// --- Lecture du repertoire
|
|
$dh = opendir($path."/");
|
|
if ($dh) {
|
|
while (false !== ($filename = readdir($dh))) {
|
|
if ($filename == '.' && $filename =='..') continue;
|
|
if (substr($filename, -4) != '.csv') continue;
|
|
$ficLength = strlen($ficClient . $numAbo);
|
|
if (substr($filename, 0, $ficLength) == $ficClient . $numAbo) {
|
|
$tabFichier[] = $filename;
|
|
$tabDates[] = substr($filename, $ficLength + 1, 8);
|
|
$tabClients[] = substr($filename, 0, $ficLength);
|
|
}
|
|
}
|
|
|
|
// Tableau des noms de fichier
|
|
sort($tabFichier);
|
|
// Tableau des dates de livraisons
|
|
$tabDates = array_unique($tabDates);
|
|
sort($tabDates);
|
|
// Tableau des Clients
|
|
$tabClients = array_unique($tabClients);
|
|
sort($tabClients);
|
|
rsort($tabFichier);
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = "Impossible d'ouvrir le dossier client";
|
|
}
|
|
}
|
|
|
|
$result = array();
|
|
if (count($tabFichier) > 0) {
|
|
$hostname = 'http://'.$_SERVER['SERVER_NAME'];
|
|
if ($_SERVER['SERVER_PORT'] != '80'){
|
|
$hostname.= ':'.$_SERVER['SERVER_PORT'];
|
|
}
|
|
foreach($tabFichier as $fichier) {
|
|
$retFichier = new ListeFichierSurv();
|
|
$retFichier->UrlFichier = $hostname.'/fichier/crm/'.$fichier;
|
|
$result[] = $retFichier;
|
|
}
|
|
}
|
|
$output = new ListeFichierSurvReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Geocodage d'une adresse
|
|
* @param string $adresse
|
|
* @param string $cp
|
|
* @param string $ville
|
|
* @param string $pays
|
|
* @return GeoCodeReturn
|
|
*/
|
|
public function geoCode($adresse, $cp, $ville, $pays='France')
|
|
{
|
|
$this->authenticate();
|
|
|
|
$ligne = date('YmdHis').";$siren;MMap AVANT";
|
|
$fp = fopen(LOG_PATH.'/accesDistant.log', 'a');
|
|
fwrite($fp,$ligne.PHP_EOL);
|
|
fclose($fp);
|
|
|
|
$mMap = new Metier_Partenaires_MMap($adresse, $cp, $ville, $pays);
|
|
|
|
$ligne=date('YmdHis').";$siren;MMap APRES";
|
|
$fp=fopen(LOG_PATH.'/accesDistant.log', 'a');
|
|
fwrite($fp,$ligne.PHP_EOL);
|
|
fclose($fp);
|
|
|
|
$geocode = new GeoCode();
|
|
$geocode->latitude = $mMap->latitudeDec;
|
|
$geocode->longitude = $mMap->longitudeDec;
|
|
$geocode->precis = $mMap->precision;
|
|
$geocode->adresseValidee = $mMap->adresseValidee;
|
|
$geocode->latitudeDeg = $mMap->latitudeDeg;
|
|
$geocode->longitudeDeg = $mMap->longitudeDeg;
|
|
|
|
$output = new GeoCodeReturn();
|
|
$output->error = $error;
|
|
$output->result = $geocode;
|
|
}
|
|
|
|
/**
|
|
* Recherche d'entreprise par leur actionnaire
|
|
* @param string $nom Raison sociale / Nom de l'actionnaire (obligatoire)
|
|
* @param string $cpVille CP, Ville
|
|
* @param string $siren Siren de l'actionnaire
|
|
* @param string $pays Pays de l'actionnaire
|
|
* @param string $pctMin Niveau de détention Minimam de l'actionnaire
|
|
* @param string $pctMax Niveau de détention Maximum de l'actionnaire
|
|
* @param integer $deb Position du curseur dans la liste des réponses (0 par défaut)
|
|
* @param integer $nbRep Nombre de réponses retournées au maximum par cette requete (20 par défaut)
|
|
* @param integer $maxRep Nombre de réponses recherchées au maximum (200 par défaut)
|
|
* @param boolean $pertinence Recherche orthographique stricte sur les noms et prénoms (si true)
|
|
* @return SearchActReturn
|
|
*/
|
|
public function searchAct($nom, $cpVille='', $siren=0, $pays='', $pctMin=0, $pctMax=100, $deb=0, $nbRep=20, $maxRep=200, $pertinence=false)
|
|
{
|
|
Metier_Util_Log::write('I',"Recherche Actionnaire de $nom, $cpVille (Max Rep=$nbRep)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
if (!empty($pays)){
|
|
$wdb = new Metier_Util_Db();
|
|
$result = $wdb->select('jo.tabPays', 'codPays3', "libPays LIKE '".$pays);
|
|
if (count($result>0)){
|
|
$pays = $result[0]['codPays3'];
|
|
} else {
|
|
$pays = '';
|
|
}
|
|
}
|
|
|
|
if (empty($cpVille)) $cpVille = '';
|
|
if (empty($siren)) $siren = '';
|
|
if (empty($pctMin)) $pctMin = 0;
|
|
if (empty($pctMax)) $pctMax = 100;
|
|
if (empty($deb)) $deb = 0;
|
|
if (empty($nbRep)) $nbRep = 20;
|
|
if (empty($maxRep)) $maxRep = 200;
|
|
if (empty($pertinence)) $pertinence = false;
|
|
|
|
$formR = array(
|
|
'type' => 'act',
|
|
'siren' => $siren,
|
|
'actNomRS' => join(' ', array($nom, $cpVille)),
|
|
'pays' => $pays,
|
|
'pctMin' => $pctMin,
|
|
'pctMax' => $pctMax,
|
|
);
|
|
|
|
$version = defined('SPHINX_ACT_VERSION') ? SPHINX_ACT_VERSION : 1;
|
|
require_once 'Metier/sphinx/rechercheFonc.php';
|
|
$etabs = rechercheAct($formR, $deb, $nbRep, $maxRep);
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabRet = array();
|
|
|
|
$reponses = $etabs['reponses'];
|
|
if (count($reponses)>0) {
|
|
foreach ($reponses as $etab) {
|
|
$act = new EntrepriseActItem();
|
|
$act->id = $etab['id'];
|
|
$act->Pertinence = $etab['Pertinence'];
|
|
$act->Siret = $etab['Siret'];
|
|
$act->Siege = $etab['Siege'];
|
|
$act->Nom = strtr($etab['Nom'],'/*',' ');
|
|
$act->Nom2 = $etab['Nom2'];
|
|
$act->Sigle = $etab['Sigle'];
|
|
$act->Enseigne = $etab['Enseigne'];
|
|
$act->Adresse = $etab['Adresse'];
|
|
$act->Adresse2 = $etab['Adresse2'];
|
|
$act->CP = $etab['CP'];
|
|
$act->Ville = $etab['Ville'];
|
|
$act->Pays = $etab['Pays'];
|
|
$act->Tel = $etab['Tel'];
|
|
$act->Fax = $etab['Fax'];
|
|
$act->FJ = $etab['FJ'];
|
|
$act->FJLib = $iInsee->getLibelleFJ($etab['FJ']);
|
|
$act->Siren = $etab['Siren'];
|
|
$act->Nic = $etab['Nic'];
|
|
$act->Actif = $etab['Actif'];
|
|
$act->NafEtab = $etab['NafEtab']; // Etablissement
|
|
$act->NafEtabLib = $iInsee->getLibelleNaf($etab['NafEtab']); // Etablissement
|
|
$act->NafEnt = $etab['NafEnt']; // Entreprise
|
|
$act->NafEntLib = $iInsee->getLibelleNaf($etab['NafEnt']);
|
|
$act->ActNomRs = $etab['ActNomRs'];
|
|
$act->ActPays = $etab['ActPays'];
|
|
$act->ActDateLien = $etab['ActDateLien'];
|
|
$act->ActActif = $etab['ActActif'];
|
|
$act->ActPmin = $etab['ActPmin'];
|
|
$tabRet[] = $act;
|
|
}
|
|
}
|
|
|
|
$output = new SearchActReturn();
|
|
$output->nbReponses = $etabs['nbReponses'];
|
|
$output->nbReponsesTotal = $etabs['nbReponsesTotal'];
|
|
$output->result = $tabRet;
|
|
|
|
if ($tabRet['nbReponses']==0) {
|
|
Metier_Util_Log::write('W', "Aucun résultat pour cette recherche !", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Commande d'une enquête sur une entreprise en France ou à l'Internationale
|
|
* @param string $siren
|
|
* @param string $infoEnq Informations pour la demande d'enquête<br/>
|
|
* InfoEnq[Entrep][Tel]<br/>
|
|
* InfoEnq[Entrep][Fax]<br/>
|
|
* InfoEnq[Entrep][AutreTel]<br/>
|
|
* InfoEnq[Entrep][Mail]<br/>
|
|
* InfoEnq[Entrep][AutreMail]<br/>
|
|
* InfoEnq[Entrep][Web]<br/>
|
|
* InfoEnq[Entrep][Rib][Banque]<br/>
|
|
* InfoEnq[Entrep][Rib][Guichet]<br/>
|
|
* InfoEnq[Entrep][Rib][Compte]<br/>
|
|
* InfoEnq[Entrep][Rib][Cle]<br/>
|
|
* InfoEnq[Encours]<br/>
|
|
* InfoEnq[NbEcheances]<br/>
|
|
* InfoEnq[AvisAssureur]<br/>
|
|
* InfoEnq[Type]<br/>
|
|
* InfoEnq[Delai]<br/>
|
|
* InfoEnq[PrecisionsChoix]<br/>
|
|
* InfoEnq[Precisions][MontantCA]<br/>
|
|
* InfoEnq[Precisions][Motif]<br/>
|
|
* InfoEnq[Precisions][Autre]<br/>
|
|
* InfoEnq[Anciennete]<br/>
|
|
* InfoEnq[AncienneteDuree]<br/>
|
|
* InfoEnq[ImpayeesChoix]<br/>
|
|
* InfoEnq[Impayees][Montant]<br/>
|
|
* InfoEnq[Impayees][Nombre]<br/>
|
|
* InfoEnq[Impayees][Date]<br/>
|
|
* InfoEnq[RetardPaiementChoix]<br/>
|
|
* InfoEnq[RetardPaiement][Montant]<br/>
|
|
* InfoEnq[RetardPaiement][Nombre]<br/>
|
|
* InfoEnq[RetardPaiement][Date]<br/>
|
|
* InfoEnq[LitigeChoix]<br/>
|
|
* InfoEnq[Litige][Precisions]<br/>
|
|
* InfoEnq[Observation]<br/>
|
|
* @param string $infoDemande Informations sur l'utilisateur<br/>
|
|
* InfoUser[Profil]<br/>
|
|
* InfoUser[ProfilAutre]<br/>
|
|
* InfoUser[Identite]<br/>
|
|
* InfoUser[Tel]<br/>
|
|
* InfoUser[Fax]<br/>
|
|
* InfoUser[Email]<br/>
|
|
* InfoUser[Ref]<br/>
|
|
* @return CommandeEnqueteReturn
|
|
*/
|
|
public function commandeEnquete($siren, $infoEnq, $infoDemande)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$infoEnq = json_decode($infoEnq);
|
|
$infoDemande = json_decode($infoDemande);
|
|
|
|
$mail = trim($infoDemande['Email']);
|
|
if ($mail=='') {
|
|
$mail=$this->User->email;
|
|
}
|
|
|
|
$dateCommande = date('YmdHis');
|
|
|
|
$tabInsert = array(
|
|
'idUser' => $this->User->id,
|
|
'source' => 'intersud', // 'greffes', 'asso', 'graydon'
|
|
'login' => $tabInfoUser['login'],
|
|
'emailCommande' => $mail,
|
|
'siren' => $siren,
|
|
'refDocument' => serialize($infoDemande),
|
|
'refCommande' => serialize($infoEnq),
|
|
'dateCommande' => $dateCommande,
|
|
// 'idClient'=> $tabInfoUser['idClient'],
|
|
);
|
|
Metier_Util_Log::write('I',"Intersud, début commande sur $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$messageInfo = print_r($infoEnq, 1).PHP_EOL.print_r($infoDemande,1).PHP_EOL;
|
|
|
|
$idClient = $this->User->idClient;
|
|
|
|
$iDbCrm = new Metier_Util_Db();
|
|
$rep = $iDbCrm->select('sdv1.clients', ' nom, racineLogin, InterSudLogin, InterSudPass', "id='$idClient'", false, MYSQL_ASSOC);
|
|
$login = trim($rep[0]['InterSudLogin']);
|
|
$pass = trim($rep[0]['InterSudPass']);
|
|
$nomClient = trim(strtoupper($rep[0]['nom']));
|
|
$strInfoCommande = "NOM et Prénom du client demandeur : ".$infoDemande['Identite'].PHP_EOL;
|
|
$strInfoCommande.= "Email du client demandeur : $mail".PHP_EOL;
|
|
$strInfoCommande.= "Tel/Fax du demandeur : ".$infoDemande['Tel'].' / '.$infoDemande['Fax'].PHP_EOL;
|
|
$strInfoCommande.= "Profil du demandeur : ".trim($infoDemande['Profil'].' '.$infoDemande['ProfilAutre']).PHP_EOL;
|
|
$typeEnqLog='enqueteDemNF';
|
|
|
|
if ($login=='' || $pass=='') {
|
|
/** Il ne s'agit pas d'un client final, on anonymise la commande **/
|
|
$login='YLENA'; // Demandes en test
|
|
$pass='WYLFE';
|
|
$nomClient=$strInfoCommande='';
|
|
$typeEnqLog='enqueteDem';
|
|
/* ENQUETES EN PROD
|
|
$login='FACTURE';
|
|
$pass='AWKROM';
|
|
*/
|
|
}
|
|
|
|
/** Connexion à l'Extranet Intersud **/
|
|
$url = 'http://www.intersud.fr/espace_client/espace_client.php';
|
|
$cookie = $referer = '';
|
|
$tabPost = array(
|
|
'login' => $login,
|
|
'pwd' => $pass,
|
|
);
|
|
$tdeb = microtime(true);
|
|
$page = getUrl($url, $cookie, $tabPost, $referer, false, '', '', 7);
|
|
if ($page['code']<>200) {
|
|
$mail = new Metier_Common_Mail();
|
|
$mail->send('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "ATTENTION : Commande d'enquete sur $siren", "Connexion impossible à la plateforme Intersud".PHP_EOL.$strInfoCommande);
|
|
throw new SoapFault('1',"Connexion impossible à la plateforme d'enquêtes");
|
|
}
|
|
|
|
$tfin = microtime(true);
|
|
$duree = $tfin-$tdeb;
|
|
$referer = $url;
|
|
$body = $page['body'];
|
|
$cookie = $page['header']['Set-Cookie'];
|
|
$intersudNomPrenom=$intersudRaisonSociale='';
|
|
if (preg_match('/<td colspan="5" class="txt_blanc" background="images_ec\/1erpageespaceclient_14\.jpg" width="274" height="22">(.*)<\/td>/Uis',$body,$matches))
|
|
$intersudNomPrenom=trim($matches[1]);
|
|
if (preg_match('/<td class="txt_blanc" colspan="7" rowspan="2" valign="middle" background="images_ec\/1erpageespaceclient_17\.jpg">(.*)<\/td>/Uis',$body,$matches))
|
|
$intersudRaisonSociale=trim($matches[1]);
|
|
Metier_Util_Log::write('I',"Intersud, connexion via $login pour $intersudRaisonSociale ($intersudNomPrenom, cookie=$cookie)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
/*
|
|
$fp=@fopen(LOG_PATH."/intersud.log", "a");
|
|
@fwrite($fp, PHP_EOL.$dateCommande.PHP_EOL.print_r($page,true).'========================================================================================================='.PHP_EOL.PHP_EOL);
|
|
@fclose($fp);
|
|
die();
|
|
*/
|
|
/** Page formulaire de demande d'enquête **/
|
|
$url='http://intersud.fr/espace_client/demande_enquete.php';
|
|
$tdeb = microtime(true);
|
|
$page = getUrl($url, $cookie, '', $referer, false, '', '', 7);
|
|
if ($page['code']<>200) {
|
|
$mail = new Metier_Common_Mail();
|
|
$mail->send('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "ATTENTION : Commande d'enquete sur $siren", "Connexion impossible au formulaire d'enquête Intersud".PHP_EOL.$strInfoCommande);
|
|
throw new SoapFault('2',"Connexion impossible à la plateforme d'enquêtes");
|
|
}
|
|
|
|
$tfin = microtime(true);
|
|
$duree+= $tfin-$tdeb;
|
|
$referer = $url;
|
|
$body = $page['body'];
|
|
|
|
$fp=@fopen(LOG_PATH.'/intersud.log', "a");
|
|
@fwrite($fp, print_r($page,true));
|
|
@fclose($fp);
|
|
$tabInterSud=array();
|
|
if (preg_match_all('/<input(?:.*)name="(.*)"(?:.*)value="(.*)"/Uim',$body,$matches)) {
|
|
foreach ($matches[1] as $i=>$field) {
|
|
$tmp=explode('"', $matches[2][$i]);
|
|
$tabInterSud[$field]=$tmp[0];
|
|
}
|
|
}
|
|
if (preg_match_all('/<input(?:.*)value="(.*)"(?:.*)name="(.*)"/Uim',$body,$matches)) {
|
|
foreach ($matches[2] as $i=>$field) {
|
|
$tmp=explode('"', $matches[1][$i]);
|
|
$tabInterSud[$field]=$tmp[0];
|
|
}
|
|
}
|
|
$ref_exp=$tabInterSud['ref_exp'];
|
|
$email_exp=$tabInterSud['email_exp'];
|
|
$tel_exp=$tabInterSud['tel_exp'];
|
|
Metier_Util_Log::write('I',"Intersud, formulaire enquête ref $ref_exp, $email_exp, $tel_exp",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$fp=@fopen(LOG_PATH.'/intersud.log', "a");
|
|
@fwrite($fp, print_r($matches,true));
|
|
@fwrite($fp, print_r($tabInterSud,true));
|
|
@fclose($fp);
|
|
|
|
/** Insertion de la commande en base **/
|
|
$ret = $iDbCrm->insert('sdv1.commandes', $tabInsert, true);
|
|
$comment = "Référence de la commande chez Scores et Décisions : i$ret - ".$dateCommande."
|
|
Date et heure de la commande : ".date('d/m/Y - H:i')."
|
|
Origine de la commande : $nomClient
|
|
$strInfoCommande
|
|
|
|
CA : ".$infoEnq['Precisions']['MontantCA']."
|
|
Motif de la demande : ".trim($infoEnq['Precisions']['Motif'].' '.$infoEnq['Precisions']['Autre'])."
|
|
Type de la demande : ".$infoEnq['Precisions']['Type']."
|
|
Anciennete de la relation : ".$infoEnq['Anciennete'].' '.$infoEnq['AncienneteDuree']."
|
|
Observations : ".$infoEnq['Observation'].PHP_EOL;
|
|
|
|
if ($infoEnq['ImpayeesChoix']<>'non')
|
|
$comment.="Impayé(s) : ".$infoEnq['Impayees']['Nombre']." impayé(s) pour un montant de ".$infoEnq['Impayees']['Montant']." en date du ".$infoEnq['Impayees']['Date'].PHP_EOL;
|
|
|
|
if ($infoEnq['RetardPaiementChoix']<>'non')
|
|
$comment.="Retard(s) de paiement : ".$infoEnq['RetardPaiement']['Nombre']." retard(s) pour un montant de ".$infoEnq['RetardPaiement']['Montant']." en date du ".$infoEnq['RetardPaiement']['Date'].PHP_EOL;
|
|
|
|
if ($infoEnq['LitigeChoix']<>'non')
|
|
$comment.="Présence de litige(s) : ".$infoEnq['Litige']['Precisions'].PHP_EOL;
|
|
|
|
$enqType=0;
|
|
$enqDelai=7;
|
|
switch (strtolower($infoEnq['Type'])) {
|
|
case 'premier': $enqType=0; $enqDelai=6; break;
|
|
case 'gold': $enqType=1; break;
|
|
case 'distrimat': $enqType=2; break;
|
|
case 'star': $enqType=3; break;
|
|
case 'avis_bancaire': $enqType=4; break;
|
|
case 'autre': $enqType=5; break;
|
|
}
|
|
|
|
/** Ajout du RIB si communiqué **/
|
|
if (@trim(implode(' ', $infoEnq['Entrep']['Rib']))<>''){
|
|
$iDbCrm->insert('sdv1.banques', array(
|
|
'siren' => $siren,
|
|
'libBanqueGuichet' => '',
|
|
'precis' => 1,
|
|
'codeBanque' => $infoEnq['Entrep']['Rib']['Banque'],
|
|
'codeGuichet' => $infoEnq['Entrep']['Rib']['Guichet'],
|
|
'numCompte' => $infoEnq['Entrep']['Rib']['Compte'].$infoEnq['Entrep']['Rib']['Cle'],
|
|
'dateSource' => $dateCommande,
|
|
), true);
|
|
}
|
|
|
|
/** Remplissage du formulaire d'enquête pour soumission à Intersud **/
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabIdentite = $iInsee->getIdentiteLight($siren);
|
|
$tabPost = array(
|
|
'soc' => $tabIdentite['Nom'],
|
|
'cible_enk' => 9, // 9
|
|
'siret' => $siren,
|
|
'acti' => '',
|
|
'soc_exp' => $tabInterSud['soc_exp'],
|
|
'type_enk' => $enqType, // 0=Premier, 1=Gold, 2=Distrimat, 3=Star, 4=Avis bancaire, 5=Autre
|
|
'nom_diri' => '',
|
|
'adr' => $tabIdentite['Adresse'],
|
|
'ref_exp' => $tabInterSud['ref_exp'],
|
|
'autre_type_enk' => '', // Texte libre
|
|
'adr2' => $tabIdentite['Adresse2'],
|
|
'delai_enk' => $enqDelai, // 6=24h, 7=72h, 8=+de5jours
|
|
'ville' => $tabIdentite['Ville'],
|
|
'cp' => $tabIdentite['CP'],
|
|
'pays' => '', // International ?
|
|
'nom_exp' => $tabInterSud['nom_exp'],
|
|
'tel' => $tabIdentite['Tel'],
|
|
'port' => $infoEnq['Entrep']['AutreTel'],
|
|
'tel_exp' => $tabInterSud['tel_exp'],
|
|
'bank' => trim(implode(' ', $infoEnq['Entrep']['Rib'])),
|
|
'int_enk' => $tabInterSud['int_enk'], // International ?
|
|
'encours' => $infoEnq['Encours'],
|
|
'nb_ech' => $infoEnq['NbEcheances'],
|
|
'delai2_enk' => $tabInterSud['delai2_enk'], // International ?
|
|
'email_exp' => $tabInterSud['email_exp'],
|
|
'cred' => '',
|
|
'comment' => urlencode($comment),
|
|
'val_ret' => $tabInterSud['val_ret'],
|
|
);
|
|
$url = 'http://intersud.fr/espace_client/demande_enquete.php';
|
|
$tdeb = microtime(true);
|
|
$page = getUrl($url, $cookie, $tabPost, $referer, false, '', '', 7);
|
|
if ($page['code']<>200) {
|
|
$mail = new Metier_Common_Mail();
|
|
$mail->send('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "ATTENTION : Commande d'enquete sur $siren", "Validation impossible du formulaire d'enquête Intersud".PHP_EOL.$strInfoCommande);
|
|
throw new SoapFault('3',"Connexion impossible à la plateforme d'enquêtes");
|
|
}
|
|
|
|
$tfin = microtime(true);
|
|
$duree+= $tfin-$tdeb;
|
|
$referer = $url;
|
|
$body = $page['body'];
|
|
|
|
$output = new CommandeEnqueteReturn();
|
|
$output->siren = $siren;
|
|
$output->emailCommande = $mail;
|
|
$output->dateCommande = $dateCommande;
|
|
$output->refCmde = 'i'.$ret;
|
|
|
|
//$strInfoCommande $mail
|
|
$mail = new Metier_Common_Mail();
|
|
$mail->send('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Commande d'enquete sur $siren", $comment.PHP_EOL.PHP_EOL.'---------------------------------'.PHP_EOL.$messageInfo.PHP_EOL.PHP_EOL.'---------------------------------'.PHP_EOL.$body);
|
|
$mail = new Metier_Common_Mail();
|
|
$mail->send('production@scores-decisions.com', $mail, "Votre demande d'enquete sur ".$tabIdentite['Nom']." ($siren)", "Votre demande d'enquête sur la société ".$tabIdentite['Nom']." a été prise en compte sous la référence i$ret - ".$dateCommande);
|
|
wsLog($typeEnqLog, $siren, 'i'.$ret.'-'.$dateCommande);
|
|
|
|
/** Gestion de la déconnexion **/
|
|
$url = 'http://intersud.fr/espace_client/index.php?code_ret=9';
|
|
$tdeb = microtime(true);
|
|
$page = getUrl($url, $cookie, '', $referer, false, '', '', 7);
|
|
$tfin = microtime(true);
|
|
$duree+= $tfin-$tdeb;
|
|
|
|
$ret = $iDbCrm->update('sdv1.commandes', array('dureeCommande'=>round($duree,3)), "idCommande=$ret");
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'ensemble des informations des dirigeants opérationnels (non statutaires) de l'entreprise
|
|
* @param string $siren Siren de l'entreprise
|
|
* @return DirigeantOp[]
|
|
*/
|
|
public function getDirigeantsOp($siren, $id = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
Metier_Util_Log::write('I',"Dirigeants opérationnels demandés pour $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
if (strlen($siren)>9 || (substr($siren,0,9)*1)<100 ){
|
|
Metier_Util_Log::write('W', "Siren $siren incorrect", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$dirs = $iInsee->getDirigeantsOp($siren, $id);
|
|
$tabRet = array();
|
|
if (count($dirs)>0){
|
|
foreach ($dirs as $nb => $dir) {
|
|
$objet = new DirigeantOp();
|
|
$objet->Id = $dir['Id'];
|
|
$objet->Code = $dir['Fonction'];
|
|
$objet->Titre = $dir['Titre'];
|
|
$objet->Societe = $dir['Societe'];
|
|
$objet->Civilite = $dir['Civilite'];
|
|
$objet->Nom = $dir['Nom'];
|
|
$objet->Prenom = $dir['Prenom'];
|
|
$objet->NomUsage = $dir['NomUsage'];
|
|
$objet->NaissDate = $dir['NaissDate'];// 07/09/1961
|
|
$objet->NaissVille = $dir['NaissVille']; // LE RUSSEY
|
|
$objet->NaissDepPays = $dir['NaissDepPays']; // LE RUSSEY
|
|
$objet->Tel = $dir['Tel'];
|
|
$objet->Fax = $dir['Fax'];
|
|
$objet->Email = $dir['Email'];
|
|
$objet->Ancien = $dir['Ancien'];
|
|
$objet->DateFct = $dir['DateFct'];
|
|
|
|
$tabRet[] = $objet;
|
|
}
|
|
}
|
|
$this->wsLog('dirigeantsOp', $siren);
|
|
Metier_Util_Log::write('I', 'Nb Dirigeants Op retournés = '. count($dirs), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
return $tabRet;
|
|
}
|
|
|
|
/**
|
|
* Liste de tous les dépôts enregistrés à l'INPI pour une entreprise
|
|
* @param string $siren Siren de l'entreprise
|
|
* @return Depot[]
|
|
*/
|
|
public function getListeDepots($siren)
|
|
{
|
|
$this->authenticate();
|
|
|
|
Metier_Util_Log::write('I',"Liste des dépots INPI pour $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
if (strlen($siren)>9 || (substr($siren,0,9)*1)<100 ){
|
|
Metier_Util_Log::write('W', "Siren $siren incorrect", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$iRncs=new Metier_Partenaires_MRncs();
|
|
$evens=$iRncs->getListeDepots($siren);
|
|
$tabRet = array();
|
|
if (count($evens)>0){
|
|
foreach ($evens as $nb=>$even){
|
|
$objet = new Depot();
|
|
$objet->CodeDepot = $even['codDepot'];
|
|
$objet->LibDepot = $even['libDepot'];
|
|
$objet->DateDepot = $even['datDepot'];
|
|
$objet->RefDepot = $even['refDepot'];
|
|
$objet->DateRncs = $even['datRncs'];
|
|
$objet->DateMAJ = $even['datSed'];
|
|
|
|
$tabRet[] = $objet;
|
|
}
|
|
}
|
|
Metier_Util_Log::write('I', 'Nb dépôts retournés = '. count($tabRet), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
return $tabRet;
|
|
}
|
|
|
|
|
|
/**
|
|
* Identite Light
|
|
* @param string $siret
|
|
* @param integer $id
|
|
* @return IdentiteLight
|
|
*/
|
|
public function getIdentiteLight($siret, $id = 0)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
if ( empty($id) ) {
|
|
$id = 0;
|
|
}
|
|
|
|
$siret = trim($siret);
|
|
$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');
|
|
}
|
|
if ($len!=14 && $len!=9) {
|
|
$this->sendError('1020');
|
|
}
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabIdentite = $iInsee->getIdentiteLight($siren, $nic, $id);
|
|
|
|
$output = new IdentiteLight();
|
|
$output->id = $tabIdentite['id'];
|
|
$output->Siret = $tabIdentite['Siret'];
|
|
$output->Siege = $tabIdentite['Siege'];
|
|
$output->Nom = $tabIdentite['Nom'];
|
|
$output->Tribunal = $tabIdentite['Tribunal'];
|
|
$output->Sigle = $tabIdentite['Sigle'];
|
|
$output->Enseigne = $tabIdentite['Enseigne'];
|
|
$output->Adresse = $tabIdentite['Adresse'];
|
|
$output->Adresse2 = $tabIdentite['Adresse2'];
|
|
$output->AdresseNum = $tabIdentite['AdresseNum'];
|
|
$output->AdresseBtq = $tabIdentite['AdresseBtq'];
|
|
$output->AdresseVoie = $tabIdentite['AdresseVoie'];
|
|
$output->AdresseRue = $tabIdentite['AdresseRue'];
|
|
$output->CP = $tabIdentite['CP'];
|
|
$output->Ville = $tabIdentite['Ville'];
|
|
$output->Tel = $tabIdentite['Tel'];
|
|
$output->Fax = $tabIdentite['Fax'];
|
|
$output->FJ = $tabIdentite['FJ'];
|
|
$output->FJ_Lib = $tabIdentite['FJ_lib'];
|
|
$output->Siren = $tabIdentite['Siren'];
|
|
$output->Nic = $tabIdentite['Nic'];
|
|
$output->Actif = $tabIdentite['Actif'];
|
|
$output->NafEtab = $tabIdentite['NafEtab'];
|
|
$output->NafEnt = $tabIdentite['NafEnt'];
|
|
$output->NafEntLib = $tabIdentite['NafEntLib'];
|
|
$output->NafEtabLib = $tabIdentite['NafEtabLib'];
|
|
$output->AutreId = $tabIdentite['AutreId'];
|
|
$output->Source = $tabIdentite['Source'];
|
|
$output->SourceId = $tabIdentite['SourceId'];
|
|
$output->Dept = $tabIdentite['Dept'];
|
|
$output->codeCommune = $tabIdentite['codeCommune'];
|
|
$output->Capital = $tabIdentite['Capital'];
|
|
$output->CapitalDev = $tabIdentite['CapitalDev'];
|
|
$output->TrancheCA = $tabIdentite['TrancheCA'];
|
|
$output->TrancheCALib = $tabIdentite['TrancheCALib'];
|
|
$output->EffEnTr = $tabIdentite['EffEnTr'];
|
|
$output->EffEnTrLib = $tabIdentite['EffEnTrLib'];
|
|
$output->EffEtTr = $tabIdentite['EffEtTr'];
|
|
$output->EffEtTrLib = $tabIdentite['EffEtTrLib'];
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Retourne les éléments du groupes
|
|
* @param string $siren
|
|
* @param int $pctMin (33, 40 ,50)
|
|
* @param boolean $stopAtIsin
|
|
* @param int $nbNiveaux
|
|
* @return string
|
|
*/
|
|
public function getGroupesArbo($siren, $pctMin=33, $stopAtIsin=false, $nbNiveaux=10)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( !in_array($pctMin, array(33, 40, 50)) && $this->User->idClient!=1 ) {
|
|
$pctMin = 33;
|
|
}
|
|
|
|
if ( empty($stopAtIsin) ) { $stopAtIsin = false; }
|
|
if ( empty($nbNiveaux) ) { $nbNiveaux = 10; }
|
|
|
|
if ( strlen($siren)!=9 || intval($siren)<100 ){
|
|
Metier_Util_Log::write('W', "Siren $siren incorrect", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
try {
|
|
$liensM = new Metier_Liens_Base($siren, 'siren');
|
|
$liensM->stopAtFirstIsin = $stopAtIsin;
|
|
$tabRet = $liensM->getTree($pctMin, $nbNiveaux);
|
|
} catch(Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$this->wsLog('groupesarbo', $siren);
|
|
return json_encode($tabRet);
|
|
}
|
|
|
|
/**
|
|
* Retourne les information du groupe, tête de pont
|
|
* @param string $siren
|
|
* @return GroupeInfos
|
|
*/
|
|
public function getGroupeInfos($siren)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( strlen($siren)!=9 || intval($siren)<100 ){
|
|
Metier_Util_Log::write('W', "Siren $siren incorrect", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$iDb = new Metier_Util_Db();
|
|
$tmp = $iDb->select('jo.etablissements_act',
|
|
'raisonSociale, enseigne, sigle, identite_pre, adr_num, adr_btq, adr_typeVoie, adr_libVoie, adr_comp, LPAD(adr_cp,5,0) AS adr_cp, adr_ville, adr_dep, adr_com, tel, fax, siren, sirenGrp',
|
|
"siren=(SELECT distinct sirenGrp FROM jo.etablissements_act WHERE siren=$siren AND siege=1) LIMIT 0,1", false, MYSQL_ASSOC);
|
|
$tabEnt = $tmp[0];
|
|
$sirenGrp = $tabEnt['siren'];
|
|
|
|
if ($sirenGrp<1000) {
|
|
throw new SoapFault('Error', 'Aucun siren de groupe');
|
|
}
|
|
|
|
/** Table des Nafs5 => Secteurs **/
|
|
$tmp = $iDb->select('jo.tabNaf5', 'codNaf2, codNaf1', '1 GROUP BY codNAf2', false, MYSQL_ASSOC);
|
|
$tabNAf2 = array();
|
|
foreach ($tmp as $tmp2) {
|
|
$tabNAf2[$tmp2['codNaf2']]=$tmp2['codNaf1'];
|
|
}
|
|
|
|
$tabNaf2Lib = array(
|
|
'A'=>'Agriculture, sylviculture et pêche',
|
|
'B'=>'Industries extractives',
|
|
'C'=>'Industrie manufacturière',
|
|
'D'=>'Production et distribution d\'électricité, de gaz, de vapeur et d\'air conditionné',
|
|
'E'=>'Production et distribution d\'eau ; assainissement, gestion des déchets et dépollution',
|
|
'F'=>'Construction',
|
|
'G'=>'Commerce ; réparation d\'automobiles et de motocycles',
|
|
'H'=>'Transports et entreposage',
|
|
'I'=>'Hébergement et restauration',
|
|
'J'=>'Information et communication',
|
|
'K'=>'Activités financières et d\'assurance',
|
|
'L'=>'Activités immobilières',
|
|
'M'=>'Activités spécialisées, scientifiques et techniques',
|
|
'N'=>'Activités de services administratifs et de soutien',
|
|
'O'=>'Administration publique',
|
|
'P'=>'Enseignement',
|
|
'Q'=>'Santé humaine et action sociale',
|
|
'R'=>'Arts, spectacles et activités récréatives',
|
|
'S'=>'Autres activités de services',
|
|
'T'=>'Activités des ménages en tant qu\'employeurs ; activités indifférenciées des ménages en tant que producteurs de biens et services pour usage propre',
|
|
'U'=>'Activités extra-territoriales',
|
|
);
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabId = $iInsee->getIdentiteEntreprise($sirenGrp);
|
|
|
|
//Chargement retour
|
|
$output = new GroupeInfos();
|
|
$output->grpNom = $tabEnt['raisonSociale'];
|
|
$output->grpEnseigne = $tabEnt['enseigne'];
|
|
$output->grpSigle = $tabEnt['sigle'];
|
|
$output->grpAdrNum = $tabEnt['adr_num'];
|
|
$output->grpAdrBtq = $tabEnt['adr_btq'];
|
|
$output->grpAdrTypeVoie = $tabEnt['adr_typeVoie'];
|
|
$output->grpadrLibVoie = $tabEnt['adr_libVoie'];
|
|
$output->grpAdrComp = $tabEnt['adr_comp'];
|
|
$output->grpAdrCP = $tabEnt['adr_cp'];
|
|
$output->grpAdrVille = $tabEnt['adr_ville'];
|
|
$output->grpAdrDep = $tabEnt['adr_dep'];
|
|
$output->grpAdrCom = $tabEnt['adr_com'];
|
|
$output->grpTel = $tabEnt['tel'];
|
|
$output->grpFax = $tabEnt['fax'];
|
|
$output->grpSiren = $tabEnt['siren'];
|
|
$output->grpTva = $tabId['TvaNumero'];
|
|
$output->grpIsin = $tabId['Isin'];
|
|
$output->grpNumRC = $tabId['numRC'];
|
|
$output->grpTribunal = $tabId['TribunalLib'];
|
|
$output->grpWeb = $tabId['Web'];
|
|
|
|
$grpNbEnt = $grpEffectif = $grpCAExp = $grpCA = $nbProcol = 0;
|
|
$grpDateCrea = $grpDateImmat = date('Ymd');
|
|
|
|
$tmp = $iDb->select('jo.etablissements_act e',
|
|
'LPAD(e.siren,9,0), e.eff_entrep, e.dateCrea_ent AS dateCrea, e.dateImmat*1 AS dateImmat, e.bilFK, e.bilFL, e.bilYP, e.ape_entrep, e.avisCs, e.procolHisto',
|
|
"e.sirenGrp=$sirenGrp AND e.siege=1", false, MYSQL_ASSOC);
|
|
|
|
$tabSirenGrp = array();
|
|
$tabSecteur = array();
|
|
$tabAvis = array();
|
|
if ( count($tmp)>0 ) {
|
|
foreach ($tmp as $tabEnt)
|
|
{
|
|
$tabSirenGrp[] = $tabEnt['siren'];
|
|
$grpNbEnt++;
|
|
|
|
if ($tabEnt['bilYP']>$tabEnt['eff_entrep'])
|
|
$grpEffectif+=$tabEnt['bilYP'];
|
|
else
|
|
$grpEffectif+=$tabEnt['eff_entrep'];
|
|
|
|
if ($tabEnt['procolHisto']*1==1) $nbProcol++;
|
|
|
|
if ($grpDateCrea>$tabEnt['dateCrea'] && $tabEnt['dateCrea']>=19000101)
|
|
$grpDateCrea=$tabEnt['dateCrea'];
|
|
|
|
if ($grpDateImmat>$tabEnt['dateImmat'] && $tabEnt['dateImmat']>=19000101)
|
|
$grpDateImmat=$tabEnt['dateImmat'];
|
|
|
|
$grpCAExp+=$tabEnt['bilFK'];
|
|
$grpCA+=$tabEnt['bilFL'];
|
|
|
|
$tabSecteur[$tabNAf2[''.substr($tabEnt['ape_entrep'],0,2)]]['nb']++;
|
|
$tabSecteur[$tabNAf2[''.substr($tabEnt['ape_entrep'],0,2)]]['ca']+=$tabEnt['bilFL'];
|
|
$tabSecteur[$tabNAf2[''.substr($tabEnt['ape_entrep'],0,2)]]['eff']+=$tabEnt['eff_entrep'];
|
|
|
|
$tabAvis[$tabEnt['avisCs']]++;
|
|
}
|
|
}
|
|
$output->grpNbProcolHisto = $nbProcol;
|
|
$output->grpCAExport = $grpCAExp;
|
|
$output->grpCA = $grpCA;
|
|
|
|
if ($grpCA>=500000000)
|
|
$output->grpGrandGroupeFr=1;
|
|
else
|
|
$output->grpGrandGroupeFr=0;
|
|
|
|
$output->grpNbEntrep = $grpNbEnt;
|
|
$output->grpEffectif = $grpEffectif;
|
|
|
|
$output->grpAnneCreation = '';
|
|
if ($grpDateCrea<$grpDateImmat)
|
|
$output->grpAnneCreation = substr($grpDateCrea,0,4);
|
|
else
|
|
$output->grpAnneCreation = substr($grpDateImmat,0,4);
|
|
|
|
//@todo : transformer le tableau
|
|
$output->avisCs = json_encode($tabAvis); // Vérifier les procol
|
|
|
|
$tabSecteur2 = array();
|
|
if ( count($tabSecteur)>0 ) {
|
|
foreach ($tabSecteur as $secteur=>$tmp) {
|
|
$info = new GroupeInfosSecteur();
|
|
$info->code = $secteur;
|
|
$info->lib = $tabNaf2Lib[$secteur];
|
|
$info->entrepNb = $tmp['nb'];
|
|
$info->entrepTx = round($tmp['nb']*100/$grpNbEnt,2);
|
|
$info->caNb = $tmp['ca'];
|
|
$info->caTx = round($tmp['ca']*100/$grpCA,2);
|
|
$info->effNb = $tmp['eff'];
|
|
$info->effTx = round($tmp['eff']*100/$grpEffectif,2);
|
|
$tabSecteur2[] = $info;
|
|
}
|
|
}
|
|
$output->secteur = $tabSecteur2; //@todo : transformer le tableau
|
|
|
|
$this->wsLog('groupeinfos', $siren);
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Liste les bilans en saisie
|
|
* @param BilanSaisieFiltre[] $filtre
|
|
* @param integer $position
|
|
* @param integer $nbRep
|
|
*/
|
|
protected function getBilanSaisie($filtre, $position = 0, $nbRep = 50)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$idUtilisateur = $this->User->id;
|
|
|
|
if (empty($position)) $position = 0;
|
|
if (empty($nbRep)) $nbRep = 50;
|
|
if ($nbRep>200) $nbRep = 200;
|
|
|
|
$bilansM = new Application_Model_FedasoBilans();
|
|
|
|
$sql = $bilansM->select()->order('dateEntree DESC');
|
|
|
|
if (is_array($filtre) && count($filtre)>0) {
|
|
foreach($filtre as $item) {
|
|
switch($item->key) {
|
|
case 'siren':
|
|
$sql->where('siren=?', $item->value);
|
|
break;
|
|
case 'etat':
|
|
|
|
break;
|
|
/**
|
|
* Si l'utilisateur est de S&d (idClient = 1) et SuperAdministeur ou
|
|
* Mode Edition dans les droits alors on permet la sélection d'un autre
|
|
* utilisateur
|
|
*/
|
|
case 'idUtilisateur':
|
|
if ($this->User->idClient==1
|
|
&& ($this->User->profil=='SuperAdministrateur'
|
|
|| $this->checkPerm('edition')) ) {
|
|
$idUtilisateur = $item->value;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//Select user id
|
|
$sql->where('idUtilisateur=?', $idUtilisateur);
|
|
|
|
//Paginate
|
|
$sql->limit($nbRep, $position);
|
|
//Get results
|
|
$results = $bilansM->fetchAll($sql)->toArray();
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
|
|
$output = array();
|
|
if (count($results)>0) {
|
|
foreach ($results as $result) {
|
|
|
|
$entrep = $iInsee->getIdentiteLight($result['siren']);
|
|
|
|
$saisie = new BilanSaisieInfos();
|
|
$saisie->raisonSociale = $entrep['raisonSociale'];
|
|
$saisie->siren = $result['siren'];
|
|
$saisie->dateCloture = $result['dateCloture']; //@todo : date format 2010-12-31
|
|
$saisie->duree = $result['duree'];
|
|
$saisie->dateIn = $result['dateEntree']; //@todo : date format 2011-08-31 12:00:01
|
|
|
|
/**
|
|
* Gestion des différents états
|
|
* 1 - dateEntree : Enregistré
|
|
* 2 - dateEnvoi : Saisie en cours
|
|
* 3 - dateRetour : Saisie
|
|
* 4 - dateChargement : Chargé en base
|
|
*
|
|
* 5 - codeRetour = : Erreur à la saisie
|
|
*/
|
|
|
|
$saisie->etat = '';
|
|
$saisie->date = '';
|
|
|
|
$output[] = $saisie;
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Liste des contacts par établissement (beta)
|
|
* @param string $siret
|
|
* @param string $filtre
|
|
* Possible value for "filtre" => fax, web, mail, tel
|
|
* @param int $position
|
|
* @param int $nbRep
|
|
* @return ContactEtReturn
|
|
* @throws SoapFault
|
|
*/
|
|
public function getContactEt($siret, $filtre = null, $position = 0, $nbRep = 200)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( strlen($siret)!=9 && strlen($siret)!=14 ) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$siren = substr($siret,0,9);
|
|
if (intval($siren)==0 ) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$nic = substr($siret,9,5);
|
|
if (intval($nic)==0) {
|
|
$nic = '00000';
|
|
}
|
|
|
|
$typeToSelect = array('fax', 'web', 'mail', 'tel');
|
|
|
|
if ($filtre !== null && !in_array($filtre, $typeToSelect)) {
|
|
throw new SoapFault('ERR', "Unknown filtre");
|
|
}
|
|
|
|
$telephonieM = new Application_Model_JoTelephonie();
|
|
$sql = $telephonieM->select()
|
|
->from($telephonieM, array(
|
|
'id',
|
|
'LPAD(siren,9,0) AS siren',
|
|
'LPAD(nic,5,0) AS nic',
|
|
'typeTel',
|
|
'infoTel',
|
|
'LPAD(telephone, 10, 0) AS telephone',
|
|
'partenaire',
|
|
"dateProvPartenaire",
|
|
'IF(dateSuppr!=0,1,0) AS deleted',
|
|
))
|
|
->where('actif=1')
|
|
->where('typeTel IN ("'.join('","', $typeToSelect).'")')
|
|
->where('siren=?',$siren);
|
|
|
|
if ( intval($nic) > 0 ) {
|
|
$sql->where('nic=?',$nic);
|
|
}
|
|
|
|
if ( $filtre != null ) {
|
|
$sql->where('typeTel=?', $filtre);
|
|
}
|
|
|
|
$sql->order('typeTel ASC');
|
|
$sql->order('dateInsert DESC')->limit($nbRep, $position);
|
|
|
|
try {
|
|
$contacts = $telephonieM->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
//Comptage
|
|
$sql = $telephonieM->select()
|
|
->from($telephonieM, 'COUNT(*) as nb')
|
|
->where('actif=1')
|
|
->where('typeTel IN ("'.join('","', $typeToSelect).'")')
|
|
->where('siren=?',$siren);
|
|
|
|
if ( intval($nic) > 0 ) {
|
|
$sql->where('nic=?',$nic);
|
|
}
|
|
|
|
$result = $telephonieM->fetchRow($sql);
|
|
$nbContacts = 0;
|
|
if ( $result !== null ) {
|
|
$nbContacts = $result->nb;
|
|
}
|
|
|
|
$list = array();
|
|
if ( $contacts->count() > 0) {
|
|
foreach ( $contacts as $item ) {
|
|
$contact = new ContactEt();
|
|
$contact->id = $item->id;
|
|
$contact->siren = $item->siren;
|
|
$contact->nic = $item->nic;
|
|
if ( in_array($item->typeTel, array('mail', 'web')) ) {
|
|
$contact->value = $item->infoTel;
|
|
$contact->description = '';
|
|
} else {
|
|
$contact->value = $item->telephone;
|
|
$contact->description = $item->infoTel;
|
|
}
|
|
$contact->type = $item->typeTel;
|
|
|
|
$contact->source = $item->partenaire;
|
|
|
|
$date = DateTime::createFromFormat('Ymd', $item->dateProvPartenaire);
|
|
$contact->date = $date->format('Y-m-d');
|
|
|
|
$contact->deleted = false;
|
|
if ($item->deleted==1) {
|
|
$contact->deleted = true;
|
|
}
|
|
|
|
$list[] = $contact;
|
|
}
|
|
}
|
|
|
|
//Return
|
|
$output = new ContactEtReturn();
|
|
$output->nbReponses = $nbContacts;
|
|
$output->result = $list;
|
|
|
|
return $output;
|
|
}
|
|
|
|
|
|
/**
|
|
* Identifiant locaux des pays
|
|
* @param string $codeCountry
|
|
* @return CountryId[]
|
|
* @throws SoapFault
|
|
*/
|
|
public function getCountryId($codeCountry)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( strlen($codeCountry)!=3 ) {
|
|
throw new SoapFault('ERR', 'codeCountry error');
|
|
}
|
|
|
|
//Retrieve data
|
|
try {
|
|
$idlocalM = new Application_Model_Sdv1TabIdLocal();
|
|
$sql = $idlocalM->select()
|
|
->where('codPays=?', $codeCountry)
|
|
->orWhere('codPays IS NULL')
|
|
->where('dateSuppr=?', '0000-00-00 00:00:00');
|
|
$row = $idlocalM->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
$output = array();
|
|
if ($row->count()>0) {
|
|
foreach ( $row as $item ) {
|
|
$struct = new CountryId();
|
|
$struct->internalId = $item->id;
|
|
$struct->name = $item->idLocal;
|
|
$struct->longname = $item->idLocalLong;
|
|
switch ( $item->idPrincipal ) {
|
|
case 0:
|
|
$struct->type = 'Secondaire';
|
|
break;
|
|
case 1:
|
|
$struct->type = 'Principal';
|
|
break;
|
|
case 2:
|
|
$struct->type = 'TVA';
|
|
break;
|
|
}
|
|
$struct->info = $item->infoIden;
|
|
$output[] = $struct;
|
|
}
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'historique des scores
|
|
* @param string $siret
|
|
* @param string $type
|
|
* @return ScoresHistoReturn
|
|
* @throws SoapFault
|
|
*/
|
|
public function getScoresHisto($siret, $type='indiscore')
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( strlen($siret)!=9 && strlen($siret)!=14 ) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$siren = substr($siret,0,9);
|
|
if ( intval($siren)==0 ) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
if( strtolower($type)=='indiscore' ) {
|
|
$type = ( $this->User->typeScore==20 ) ? 'indiScore20' : 'indiScore';
|
|
}
|
|
|
|
$scoresDb = new Application_Model_JoScoresSurveillance();
|
|
|
|
$sql1 = $scoresDb->select()
|
|
->from(array('j'=>'scores_surveillance'), array("j.$type", 'j.encours', 'j.indiScoreDate', 'j.sourceModif'), 'jo')
|
|
->where('siren=?',$siren)
|
|
->where('indiScoreDate >= (CURDATE() - INTERVAL 5 YEAR)')
|
|
->group('indiScoreDate');
|
|
|
|
$sql2 = $scoresDb->select()
|
|
->from(array('h'=>'scores_surveillance'), array("h.$type", 'h.encours', 'h.indiScoreDate', 'h.sourceModif'), 'historiques')
|
|
->where('siren=?',$siren)
|
|
->where('indiScoreDate >= (CURDATE() - INTERVAL 5 YEAR)')
|
|
->group('indiScoreDate');
|
|
|
|
$query = $scoresDb->select()
|
|
->union(array($sql1, $sql2))
|
|
->group('indiScoreDate')
|
|
->order('indiScoreDate DESC');
|
|
|
|
try {
|
|
$rows = $scoresDb->fetchAll($query);
|
|
} catch(Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$motifLib = array(
|
|
'ajout' => "Initialisation",
|
|
'ancien' => "Score trop ancien",
|
|
'bilans1' => "Publication bilan",
|
|
'bilans2' => "Publication bilan",
|
|
'bilansasso'=> "Publication bilan Association",
|
|
'bodacc' => "Publication Bodacc",
|
|
'collecte' => "Publication JAL ou Greffe",
|
|
'dirigeants'=> "Modification de l'administration",
|
|
'impayes' => "Informations de paiements",
|
|
'insee' => "Modification identitaires INSEE",
|
|
'jour' => "Modifications identitaires",
|
|
'liens' => "Mise à jour de la structure du groupe",
|
|
'modifenc' => "Autre modification identitaire",
|
|
'privileges'=> "Mise à jour des privilèges",
|
|
'regulier' => "Informations de paiements",
|
|
'rncs' => "Modifications identitaires RNCS",
|
|
'default' => "Modification identitaire",
|
|
);
|
|
|
|
$list = array();
|
|
|
|
foreach($rows as $row) {
|
|
$item = new ScoresHisto();
|
|
$item->date = $row->indiScoreDate;
|
|
$item->value = $row->{$type};
|
|
$item->label = $motifLib[$row->sourceModif];
|
|
$item->encours = round($row->encours/1000,1);
|
|
$list[] = $item;
|
|
}
|
|
|
|
$output = new ScoresHistoReturn();
|
|
$output->type = $type;
|
|
$output->nbReponses = count($list);
|
|
$output->result = $list;
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Liste des établissements d'une entreprise
|
|
* @param string $siren Siren de l'entreprise
|
|
* @param integer $departement Limiter aux établissements du departement
|
|
* @param integer $actif Otpionnel 1=Uniquements les actifs, 0=inactifs, Néant=Tous
|
|
* @param integer $position
|
|
* @param integer $nbRep
|
|
*
|
|
* @return EtablissementsGeoReturn
|
|
*/
|
|
public function getEtablissementsGeo($siren, $dep = 0, $actif = -1, $position = 0, $nbRep = 20)
|
|
{
|
|
$this->authenticate();
|
|
$this->permission('etablissements');
|
|
|
|
//Initialisation
|
|
if (empty($dep)) { $dep = 0; }
|
|
if (!in_array($actif, array(0,1))) { $actif = -1; }
|
|
if (empty($position)) { $position = 0; }
|
|
if (empty($nbRep)) { $nbRep = 20; }
|
|
|
|
$departement = $dep;
|
|
|
|
if (strlen($siren)!=9 || intval($siren)==0 ) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$iDb = new Metier_Util_Db();
|
|
|
|
$iInsee = new Metier_Insee_MInsee($iDb);
|
|
$rep = $iInsee->getEtablissements($siren, '', $position, $nbRep, 200, $departement, $actif);
|
|
$etabs = $rep['reponses'];
|
|
$nbReponses = $rep['nbReponsesTotal'];
|
|
|
|
$result = array();
|
|
if (count($etabs)>0) {
|
|
foreach ($etabs as $nb => $etab) {
|
|
$etablissement = new EtablissementGeo();
|
|
$etablissement->id = $etab['id'];
|
|
$etablissement->Siege = $etab['Siege'];
|
|
$etablissement->Enseigne = $etab['Enseigne'];
|
|
$etablissement->Adresse = $etab['Adresse'];
|
|
$etablissement->Adresse2 = $etab['Adresse2'];
|
|
$etablissement->CP = $etab['CP'];
|
|
$etablissement->Ville = $etab['Ville'];
|
|
$etablissement->Tel = $etab['Tel'];
|
|
$etablissement->Fax = $etab['Fax'];
|
|
$etablissement->Nic = $etab['Nic'];
|
|
$etablissement->Actif = $etab['Actif'];
|
|
$etablissement->NafEtab = $etab['NafEtab'];
|
|
$etablissement->NafEtabLib = $etab['NafEtabLib'];
|
|
$etablissement->EffEtTr = $etab['EffEtTr'];
|
|
$etablissement->EffEtTrLib = $etab['EffEtTrLib'];
|
|
|
|
$adresse = $iInsee->getIdentiteLight($siren, $etab['Nic']);
|
|
$mMap = new Metier_Partenaires_MMap(false, $iDb);
|
|
$mMap->geoCodeAdresse($adresse['AdresseNum'], '', $adresse['AdresseVoie'],
|
|
$iInsee->getCodeVoie($adresse['AdresseVoie']), $adresse['AdresseRue'],
|
|
$etab['CP'], $adresse['Ville'], 'France');
|
|
|
|
$etablissement->GeoLatitude = $mMap->latitudeDec;
|
|
$etablissement->GeoLongitude = $mMap->longitudeDec;
|
|
$etablissement->GeoAltitude = $mMap->altitude;
|
|
$etablissement->GeoPrecis = $mMap->precision;
|
|
|
|
$result[] = $etablissement;
|
|
}
|
|
}
|
|
|
|
$this->wsLog('etablissements', $siren);
|
|
|
|
$output = new EtablissementsGeoReturn();
|
|
$output->nbReponses = $nbReponses;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Liste des événements RNCS
|
|
* @param string $companyId
|
|
* @throws SoapFault
|
|
* @return RncsEven[]
|
|
*/
|
|
public function getRncsEven($companyId)
|
|
{
|
|
$this->authenticate();
|
|
|
|
try {
|
|
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
|
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$sql = $db->select()->from('rncs_even', '*', 'jo')
|
|
->join('tabEvenRncs', 'rncs_even.codeEven = tabEvenRncs.codeEven', array('libEven'), 'jo')
|
|
->where('rncs_even.siren=?', $companyId);
|
|
$result = $db->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$evenList = array();
|
|
if (count($result) > 0) {
|
|
foreach ($result as $item) {
|
|
$even = new RncsEven();
|
|
$even->Code = $item->codeEven;
|
|
$even->Label = $item->libEven;
|
|
$even->Date = $item->dateDepot;
|
|
$evenList[] = $even;
|
|
}
|
|
}
|
|
|
|
return $evenList;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liste des jugements RNCS
|
|
* @param string $companyId
|
|
* @throws SoapFault
|
|
* @return RncsJugement[]
|
|
*/
|
|
public function getRncsJugement($companyId)
|
|
{
|
|
$this->authenticate();
|
|
|
|
try {
|
|
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
|
$db->setFetchMode(Zend_Db::FETCH_OBJ);
|
|
$sql = $db->select()->from('rncs_jugements', array('siren', 'codeJugement', 'dateEffet', 'typeDate', 'dateInsert'), 'jo')
|
|
->join('tabJugeRncs', 'rncs_jugements.codeJugement = tabJugeRncs.codJugement', array('libJugement'), 'jo')
|
|
->where('rncs_jugements.siren=?', $companyId);
|
|
$result = $db->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$evenList = array();
|
|
if (count($result) > 0) {
|
|
foreach ($result as $item) {
|
|
$even = new RncsJugement();
|
|
$even->Code = $item->codeJugement;
|
|
$even->Label = $item->libJugement;
|
|
$even->Type = $item->typeDate;
|
|
$even->Date = $item->dateEffet;
|
|
$evenList[] = $even;
|
|
}
|
|
}
|
|
|
|
return $evenList;
|
|
}
|
|
} |