webservice/library/WsScore/WsInterne.php
2010-11-18 17:19:25 +00:00

1601 lines
54 KiB
PHP

<?php
require_once realpath(dirname(__FILE__)).'/functions.php';
require_once realpath(dirname(__FILE__)).'/Types/InterneTypes.php';
require_once 'Metier/insee/classMInsee.php';
require_once 'Metier/insee/classMSirene.php';
require_once 'Metier/partenaires/classMBilans.php';
require_once 'Metier/partenaires/classMBourse.php';
require_once 'Metier/partenaires/classMLiens.php';
require_once 'Metier/partenaires/classMTva.php';
require_once 'Metier/partenaires/classMMap.php';
require_once 'Metier/partenaires/classMGreffes.php';
require_once 'Metier/partenaires/classMPrivileges.php';
require_once 'Metier/scores/classMFinancier.php';
require_once 'Metier/scores/classMSolvabilite.php';
require_once 'Metier/tmp/configMRatios.php';
require_once 'framework/mail/sendMail.php';
class WsInterne
{
protected $dbConfig;
protected $iDbCrm;
protected $tabInfoUser;
function __construct()
{
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH .
'/configs/databases.ini', APPLICATION_ENV);
$this->dbConfig = $dbConfig->db;
$this->iDbCrm = new WDB('sdv1');
}
/**
* checkAuth
* @param string $login
* @param string $password
* @param string $ipConnexion
*/
protected function checkAuth($login, $password, $ipConnexion)
{
$rep = $this->iDbCrm->select(//'utilisateurs', 'login, id, email, password, idClient, typeCompte, filtre_ip, civilite, nom, prenom, tel, fax, mobile, profil, raisonSociale, siret, adrNum, adrIndRep, adrTypeVoie, adrLibVoie, adrCp, adrVille, adrComp, tel, fax, mobile, pref, profil, dateInscription, dateValidation, nombreConnexions, dateDerniereConnexion, droits, referenceParDefaut, nbReponses, formatMail, dateDebutCompte, dateFinCompte, maxFicheId', "login='$login' AND actif=1", true, MYSQL_ASSOC);
'utilisateurs u, clients c',
'u.login, u.id, u.email, u.password, u.idClient, u.typeCompte, u.actif, u.filtre_ip, u.civilite, u.nom, u.prenom, u.tel, u.fax, u.mobile, u.profil, u.raisonSociale, u.siret, u.adrNum, u.adrIndRep, u.adrTypeVoie, u.adrLibVoie, u.adrCp, u.adrVille, u.adrComp, u.tel, u.fax, u.mobile, u.pref, u.profil, u.dateInscription, u.dateValidation, u.nombreConnexions, u.dateDerniereConnexion, u.droits, u.referenceParDefaut, u.nbReponses, u.formatMail, u.dateDebutCompte, u.dateFinCompte, u.maxFicheId, c.droits AS droitsClients, c.timeout',
"u.login='$login' AND u.idClient=c.id AND u.actif=1 AND u.deleted=0 AND c.actif='Oui'",
true, MYSQL_ASSOC);
$tabRep = $rep[0];
if (count($rep)>0)
{
if ($tabRep['password']==$password ||
$tabRep['password']==md5($password) ||
$password==md5($login.'|'.$tabRep['password']) ||
(substr($password,0,7)=='iponly:' && checkPlagesIp($tabRep['filtre_ip'], substr($password,7)))) // Controle par IP
{
$timeOutSec=$tabRep['timeout']*60;
if ($timeOutSec==0) $timeOutSec=1800;
$this->tabInfoUser=array(
'login'=> $login,
'id'=> $tabRep['id'],
'email'=> $tabRep['email'],
'typeCompte'=> $tabRep['typeCompte'],
'idClient'=> $tabRep['idClient'],
'filtre_ip'=> $tabRep['filtre_ip'],
'ipPasserelle'=> '',
'ipConnexion'=> $ipConnexion,
'civilite'=> $tabRep['civilite'],
'nom'=> $tabRep['nom'],
'prenom'=> $tabRep['prenom'],
'raisonSociale'=> $tabRep['raisonSociale'],
'siret'=> $tabRep['siret'],
'adrNum'=> $tabRep['adrNum'],
'adrIndRep'=> $tabRep['adrIndRep'],
'adrTypeVoie'=> $tabRep['adrTypeVoie'],
'adrLibVoie'=> $tabRep['adrLibVoie'],
'adrCp'=> $tabRep['adrCp'],
'adrVille'=> $tabRep['adrVille'],
'adrComp'=> $tabRep['adrComp'],
'tel'=> $tabRep['tel'],
'fax'=> $tabRep['fax'],
'mobile'=> $tabRep['mobile'],
'pref'=> $tabRep['pref'],
'profil'=> $tabRep['profil'],
'dateInscription'=> $tabRep['dateInscription'],
'dateValidation'=> $tabRep['dateValidation'],
'nombreConnexions'=> $tabRep['nombreConnexions'],
'dateDerniereConnexion'=> $tabRep['dateDerniereConnexion'],
'droits'=> $tabRep['droits'],
'droitsClients'=> $tabRep['droitsClients'],
'timeout'=> $timeOutSec,
'nbReponses'=> $tabRep['nbReponses'],
'formatMail'=> $tabRep['formatMail'],
'referenceParDefaut'=> $tabRep['referenceParDefaut'],
'dateDebutCompte'=> $tabRep['dateDebutCompte'],
'dateFinCompte'=> $tabRep['dateFinCompte'],
'maxFicheId'=> $tabRep['maxFicheId'],
);
$tabTmp = $this->iDbCrm->select('clients', 'typeScore', 'id='.$tabRep['idClient'], true, MYSQL_ASSOC);
$tabRep = $tabTmp[0];
$this->tabInfoUser['typeScore'] = $tabRep['typeScore'];
debugLog('W',"CheckAuth $login/$password OK", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return true;
}
debugLog('W',"CheckAuth $login/$password incorrect (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return false;
}
debugLog('W',"CheckAuth $login/$password inexistant ou inactif (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return false;
}
/**
* Enregistrement des informations saisie manuellement
* @param string $siret
* @param int $idEntreprise
* @param array $tabInfos
*/
public function setInfosEntrep( $siret, $idEntreprise, $tabInfos )
{
}
/**
* Commande de bilan
* @param InfoCommandeBilan $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdBilanReturn
*/
public function setCmdBilan( InfoCommandeBilan $infoCommande, InfoDemandeur $infoDemandeur )
{
}
/**
* Renvoi des informations sur une commande de bilan
* @param string $reference
* @return CmdBilanReturn
*/
public function getCmdBilan( $reference )
{
}
/**
* Commande d'acte
* @param InfoCommandeActe $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdActeReturn
*/
public function setCmdActe( $infoCommande, $infoDemandeur )
{
}
/**
* Renvoi des informations sur une commande d'acte
* @param string $reference
* @return CmdActeReturn
*/
public function getCmdActe( $reference ){}
/**
* Commande de kbis
* @param InfoCommandeKbis $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdKbisReturn
*/
public function setCmdKbis(InfoCommandeKbis $infoCommande, InfoDemandeur $infoDemandeur )
{
$error = new ErrorType();
$ref = new RefCommande();
//Vérifier les informations
switch($infoCommande->mode)
{
case 'courrier': break;
case 'mail': break;
default:
exit; break;
}
if (empty($infoCommande->siren))
{
$error->errnum = 0;
$error->errmsg = 'Erreur SIREN invalide';
}
else
{
$login = $_SERVER['PHP_AUTH_USER'];
// Insertion des données commande
$dataCommandes = array(
'user_login' => $login,
'user_email' => '',
'type' => 'kbis',
'demandeurReference' => $infoDemandeur->reference,
'demandeurEmail' => $infoDemandeur->email,
'demandeurTel' => $infoDemandeur->tel,
'demandeurNom' => $infoDemandeur->nom,
'demandeurService' => $infoDemandeur->service,
'demandeurSociete' => $infoDemandeur->societe,
'demandeurAdresse' => $infoDemandeur->adresse,
'demandeurCp' => $infoDemandeur->cp,
'demandeurVille' => $infoDemandeur->ville,
'infoCommande' => serialize($infoCommande)
);
try {
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commande = new Application_Model_Commandes();
$commande_id = $commande->insert($dataCommandes);
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
}
if ($commande_id)
{
//Enregistrement des détails de commande
$dataCommandesKbis = array(
'commande_id' => $commande_id,
'siren' => $infoCommande->siren,
'raisonSociale' => '',
'fichier' => '',
'partenaireRequete' => '',
'partenaireReponse' => '',
);
try {
$commandeKbisTable = new Application_Model_CommandesPieces();
$commandeKbisTable->insert($dataCommandesKbis);
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
}
try {
$row = $commande->find($commande_id);
$data = $row->current();
$ref->reference = $data->id;
$ref->dateCommande = $data->date_added;
$ref->dateMaj = $data->date_updated;
$ref->dateReception = $data->date_closed;
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
$error->errnum = 0;
$error->errmsg = "Commande Introuvable";
}
}
else
{
$error->errnum = 0;
$error->errmsg = "Erreur enregistrement commande";
}
}
$output = new CmdKbisReturn();
$cmd = new CmdKbisDetail();
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
$cmd->refCommande = $ref;
$output->commande = $cmd;
$output->error = $error;
return $output;
}
/**
* Renvoi des informations sur une commande de Kbis
* @param string $reference
* @return CmdKbisReturn
*/
public function getCmdKbis( $reference ){}
/**
* Commande de statut association
* @param InfoCommandeAsso $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdAssoReturn
*/
public function setCmdAsso( $infoCommande, $infoDemandeur ){}
/**
* Renvoi des informations sur une commande association
* @param string $reference
* @return CmdAssoReturn
*/
public function getCmdAsso( $reference ){}
/**
* Commande de privilèges et nantissements par email
* @param InfoCommandePieces $infoCommande
* @param InfoDemandeur $infoDemandeur
* @return CmdPiecesReturn
*/
public function setCmdPieces( $infoCommande, $infoDemandeur )
{
$error = new ErrorType();
$ref = new RefCommande();
if (!empty($infoCommande->siren))
{
$login = $_SERVER['PHP_AUTH_USER'];
//Vérification SIREN
//Vérification email - Si infoDemandeur->email vide alors on prend
//user_email
// Insertion des données commande
$dataCommandes = array(
'user_login' => $login,
'user_email' => '',
'type' => 'pieces',
'demandeurReference' => $infoDemandeur->reference,
'demandeurEmail' => $infoDemandeur->email,
'demandeurTel' => $infoDemandeur->tel,
'demandeurNom' => $infoDemandeur->nom,
'demandeurService' => $infoDemandeur->service,
'demandeurSociete' => $infoDemandeur->societe,
'demandeurAdresse' => $infoDemandeur->adresse,
'demandeurCp' => $infoDemandeur->cp,
'demandeurVille' => $infoDemandeur->ville,
'infoCommande' => serialize($infoCommande)
);
try {
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commande = new Application_Model_Commandes();
$commande_id = $commande->insert($dataCommandes);
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
}
if ($commande_id)
{
//Enregistrement des détails de commande
$dataCommandesPieces = array(
'commande_id' => $commande_id,
'siren' => $infoCommande->siren,
'raisonSociale' => '',
'fichier' => '',
);
try {
$commandePieces = new Application_Model_CommandesPieces();
$commandePieces->insert($dataCommandesPieces);
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
}
try {
$row = $commande->find($commande_id);
$data = $row->current();
$ref->reference = $data->id;
$ref->dateCommande = $data->date_added;
$ref->dateMaj = $data->date_updated;
$ref->dateReception = $data->date_closed;
} catch (Zend_Exception $e) {
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
$error->errnum = 0;
$error->errmsg = "Commande Introuvable";
}
}
else
{
$error->errnum = 0;
$error->errmsg = "Erreur enregistrement commande";
}
}
else
{
$error->errnum = 0;
$error->errmsg = 'Erreur SIREN invalide';
}
$output = new CmdPiecesReturn();
$cmd = new CmdPiecesDetail();
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
$cmd->refCommande = $ref;
$output->error = $error;
return $output;
}
/**
* Renvoi des informations sur une commande pièces
* @param string $reference
* @return CmdPiecesReturn
*/
public function getCmdPieces( $reference )
{
list($typeCommande, $idCommande) = explode('-', $reference);
try {
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commandeTable = new Application_Model_Commandes();
$select = $commandeTable->select()
->where('type = ?', 'pieces')
->where('id = ?', $idCommande);
$commandeRowset = $commandeTable->fetchAll($select);
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
}
$error = new ErrorType();
$ref = new RefCommande();
$infoCommande = new InfoCommandePieces();
$infoDemandeur = new InfoDemandeur();
if ( $commandeRowset->count()>0 )
{
$commande = $commandeRowset->current();
$selectEven = $commandeTable->select()
->order('date_added DESC')->limit(1);
$evenRowset = $commande->findDependentRowset(
'Application_Model_CommandesEven', null, $selectEven);
$info = '';
if($evenRowset->count()>0){
$even = $evenRowset->current();
$info = $even->commentaire;
}
$ref->reference = strtoupper($commande->type).'-'.$commande->id;
$ref->dateCommande = $commande->date_added;
$ref->dateMaj = $commande->date_updated;
$ref->dateReception = $commande->date_closed;
$ref->info = $info;
$ref->fichier = ''; // @todo : Détecter le fichier
$ref->login = $commande->user_login;
$infoCommande = unserialize($commande->infoCommande);
$infoDemandeur->reference = $commande->demandeurReference;
$infoDemandeur->email = $commande->demandeurEmail;
$infoDemandeur->tel = $commande->demandeurTel;
$infoDemandeur->nom = $commande->demandeurNom;
$infoDemandeur->service = $commande->demandeurService;
$infoDemandeur->societe = $commande->demandeurSociete;
$infoDemandeur->adresse = $commande->demandeurAdresse;
$infoDemandeur->cp = $commande->demandeurCp;
$infoDemandeur->ville = $commande->demandeurVille;
}
else
{
$error->errnum = 0;
$error->errmsg = 'Référence inconnue';
}
$output = new CmdPiecesReturn();
$cmd = new CmdPiecesDetail();
$cmd->refCommande = $ref;
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
$output->commande = $cmd;
$output->error = $error;
return $output;
}
/**
* Retourne la liste des commandes de pièces ainsi que leur détails
* @param CmdFiltrePieces $filtre
* @param int $position
* @param int $nbRep
* @return ListeCmdPiecesReturn
*/
public function getListeCmdPieces( $filtre, $position = 0, $nbRep = 20 )
{
$error = new ErrorType();
//Traitements des filtres pour générer la requête SQL
//Selection
$nbCommandes = 0;
try
{
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$commandeTable = new Application_Model_Commandes();
$select = $commandeTable->select()->where('type = ?', 'pieces');
$countRowset = $commandeTable->fetchAll($select);
$nbCommandes = $countRowset->count();
$select->order('date_added DESC')->limit($nbRep, $position);
$commandeRowset = $commandeTable->fetchAll($select);
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
$error->errnum = 1;
$error->errmsg = 'Erreur';
}
if ( $commandeRowset->count()>0 )
{
$liste = array();
foreach ($commandeRowset as $commande)
{
$selectEven = $commandeTable->select()
->order('date_added DESC')->limit(1);
$evenRowset = $commande->findDependentRowset(
'Application_Model_CommandesEven', null, $selectEven);
$info = '';
if($evenRowset->count()>0){
$even = $evenRowset->current();
$info = $even->commentaire;
}
$ref = new RefCommande();
$ref->reference = strtoupper($commande->type).'-'.$commande->id;
$ref->dateCommande = $commande->date_added;
$ref->dateMaj = $commande->date_updated;
$ref->dateReception = $commande->date_closed;
$ref->info = $info;
$ref->fichier = ''; // @todo : Détecter le fichier
$ref->login = $commande->user_login;
$infoCommande = new InfoCommandePieces();
$infoCommande = unserialize($commande->infoCommande);
$infoDemandeur = new InfoDemandeur();
$infoDemandeur->reference = $commande->demandeurReference;
$infoDemandeur->email = $commande->demandeurEmail;
$infoDemandeur->tel = $commande->demandeurTel;
$infoDemandeur->nom = $commande->demandeurNom;
$infoDemandeur->service = $commande->demandeurService;
$infoDemandeur->societe = $commande->demandeurSociete;
$infoDemandeur->adresse = $commande->demandeurAdresse;
$infoDemandeur->cp = $commande->demandeurCp;
$infoDemandeur->ville = $commande->demandeurVille;
$cmd = new CmdPiecesDetail();
$cmd->refCommande = $ref;
$cmd->infoCommande = $infoCommande;
$cmd->infoDemandeur = $infoDemandeur;
$liste[] = $cmd;
}
}
$output = new ListeCmdPiecesReturn();
$output->error = $error;
$output->nbCommandes = $nbCommandes;
$output->liste = $liste;
return $output;
}
/**
* Liste des bilans
* @param string $siren
* @param string $waldec
* @param int $idEntreprise
* @return ListeBilan
*/
public function getListeBilan( $siren, $waldec = null, $idEntreprise = null ){}
/**
* Liste des actes
* @param string $siren
* @return ListeActe
*/
public function getListeActe( $siren ){}
/**
* Retourne la liste des statuts de commande
* @param string $type
* @return CmdStatut[]
*/
public function getListeCmdStatut( $type )
{
Zend_Registry::get('WsLogger')->info("getListeStatut - ".$type);
try {
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$dbStatut = new Application_Model_CommandesStatut();
$result = $dbStatut->fetchAll(array("commande_type = '$type'"));
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
}
$listeStatut = array();
if (count($result)>0)
{
foreach($result as $r)
{
$statut = new CmdStatut();
$statut->code = $r['code'];
$statut->lib = $r['libelle'];
$listeStatut[] = $statut;
}
}
return $listeStatut;
}
/**
* Spécifier un état défini pour une commande
* (avec déclenchement d'une action)
* @param int $reference
* @param int $statutCode
* @return bool
*/
public function setCmdStatut( $reference, $statutCode)
{
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$dbStatut = new Application_Model_CommandesStatut();
$row = $dbStatut->fetchRow(array("code = '$statutCode'"));
if ( count($row)>0 && $this->setCommandeEven($reference, $row['lib']) )
{
if (!empty($row['action'])){
switch($row['action']){
case 'CLOSE':
//date_closed
break;
}
}
return true;
} else {
return false;
}
}
/**
* Spécifier un état pour une commande
* @param int $reference
* @param string $comment
* @return bool
*/
public function setCmdEven ( $reference, $comment )
{
$login = $_SERVER['PHP_AUTH_USER'];
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
try {
//Vérifier que la commande existe avec la référence fournie
$commandeTable = new Application_Model_Commandes();
$commandeRowset = $commandeTable->find($reference);
if ($commandeRowset->count()>0)
{
$commande = $commandeRowset->current();
//Enregistrer l'événement
$commandeEvenTable = new Application_Model_CommandesEven();
$insert = $commandeEvenTable->createRow();
$insert->commande_id = $commande->id;
$insert->commentaire = $comment;
$insert->user_login = $login;
$insert->save();
//Mettre à jour la commande
$commande->date_updated = date('Y-m-d H:i:s');
$commande->save();
return true;
} else {
return false;
}
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
return false;
}
}
/**
* Ajout du nom de fichier liée à la commande
* @param int $reference
* @param string $filename
* @return bool
*/
public function setCmdDocument( $reference, $filename )
{
$login = $_SERVER['PHP_AUTH_USER'];
$db = Zend_Db::factory($this->dbConfig->Commandes);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
try {
//Vérifier que la commande existe avec la référence fournie
$commandeTable = new Application_Model_Commandes();
$commandeRowset = $commandeTable->find($reference);
if ($commandeRowset->count()>0)
{
$commande = $commandeRowset->current();
switch($commande->type)
{
case 'pieces':
$infoCommandePieces = $commande->findDependentRowset('Application_Model_CommandesPieces');
if ($infoCommandePieces->count()>0)
{
//Update informations pieces
$commandePieces = $infoCommandePieces->current();
$commandePieces->fichier = $filename;
$commandePieces->save();
//Mettre à jour la commande
$commande->date_updated = date('Y-m-d H:i:s');
$commande->save();
return true;
}
break;
case 'default':
return false;
break;
}
} else {
return false;
}
}
catch (Zend_Db_Adapter_Exception $e)
{
Zend_Registry::get('WsLogger')
->err(__FUNCTION__.' - '.$e->getMessage());
return false;
}
}
/**
* Récupère les informations du profil connecté
* @param string $login
* @param string $ipUtilisateur
* @return InfosLoginReturn
*/
public function getInfosLogin($login, $ipUtilisateur = '')
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
if (empty($ipUtilisateur)) $ipUtilisateur = $_SERVER['REMOTE_ADDR'];
$error = new ErrorType();
debugLog('I',"getInfosLogin pour $login (IP=$ipUtilisateur)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
//L'utilisateur qui demande les informations est différent
if ($this->tabInfoUser['login']<>$login &&
( $this->tabInfoUser['profil']=='Administrateur' ||
$this->tabInfoUser['profil']=='SuperAdministrateur') )
{
//debugLog('I',"getInfosLogin - Un administrateur veut il des infos sur un login",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
/** Un administrateur veut il des infos sur un login ? **/
$rep = $this->iDbCrm->select(
'utilisateurs u, clients c',
'u.login, u.id, u.email, u.password, u.idClient, u.typeCompte, u.actif, u.filtre_ip, u.civilite, u.nom, u.prenom, u.tel, u.fax, u.mobile, u.profil, u.raisonSociale, u.siret, u.adrNum, u.adrIndRep, u.adrTypeVoie, u.adrLibVoie, u.adrCp, u.adrVille, u.adrComp, u.tel, u.fax, u.mobile, u.pref, u.profil, u.dateInscription, u.dateValidation, u.nombreConnexions, u.dateDerniereConnexion, u.droits, u.referenceParDefaut, u.nbReponses, u.formatMail, u.dateDebutCompte, u.dateFinCompte, u.maxFicheId, c.droits AS droitsClients, c.timeout',
"u.login='$login' AND u.idClient=c.id AND u.deleted=0",
true, MYSQL_ASSOC
);
$tabRep = $rep[0];
if (count($rep)>0)
{
$timeOutSec=$tabRep['timeout']*60;
if ($timeOutSec==0) $timeOutSec=1800;
$rep = array(
'login'=> $login,
'id'=> $tabRep['id'],
'email'=> $tabRep['email'],
'typeCompte'=> $tabRep['typeCompte'],
'idClient'=> $tabRep['idClient'],
'filtre_ip'=> $tabRep['filtre_ip'],
'civilite'=> $tabRep['civilite'],
'nom'=> $tabRep['nom'],
'prenom'=> $tabRep['prenom'],
'raisonSociale'=> $tabRep['raisonSociale'],
'siret'=> $tabRep['siret'],
'adrNum'=> $tabRep['adrNum'],
'adrIndRep'=> $tabRep['adrIndRep'],
'adrTypeVoie'=> $tabRep['adrTypeVoie'],
'adrLibVoie'=> $tabRep['adrLibVoie'],
'adrCp'=> $tabRep['adrCp'],
'adrVille'=> $tabRep['adrVille'],
'adrComp'=> $tabRep['adrComp'],
'tel'=> $tabRep['tel'],
'fax'=> $tabRep['fax'],
'mobile'=> $tabRep['mobile'],
'pref'=> $tabRep['pref'],
'profil'=> $tabRep['profil'],
'dateInscription'=> $tabRep['dateInscription'],
'dateValidation'=> $tabRep['dateValidation'],
'nombreConnexions'=> $tabRep['nombreConnexions'],
'dateDerniereConnexion'=> $tabRep['dateDerniereConnexion'],
'droits'=> $tabRep['droits'],
'droitsClients'=> $tabRep['droitsClients'],
'timeout'=> $timeOutSec,
'nbReponses'=> $tabRep['nbReponses'],
'formatMail'=> $tabRep['formatMail'],
'reference'=> $tabRep['referenceParDefaut'],
'dateDebutCompte'=> $tabRep['dateDebutCompte'],
'dateFinCompte'=> $tabRep['dateFinCompte'],
'maxFicheId'=> $tabRep['maxFicheId'],
);
$tabTmp = $this->iDbCrm->select('clients', 'typeScore', 'id='.$tabRep['idClient'], true, MYSQL_ASSOC);
$tabRep = $tabTmp[0];
$rep['typeScore'] = $tabRep['typeScore'];
}
}
else
{
//Identification utilisateur
$connected = true;
if (trim($this->tabInfoUser['filtre_ip'])<>'')
{
//debugLog('I',"getInfosLogin test filtre IP",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$connected = checkPlagesIp($this->tabInfoUser['filtre_ip'], $ipUtilisateur);
if (!$connected)
{
debugLog('I',"getInfosLogin Adresse IP $ipUtilisateur non declaree pour le compte $login",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$error->errnum = 10818;
$error->errmsg = "Adresse IP $ipUtilisateur non declaree pour ce compte. Contactez votre administrateur !";
}
}
$rep = array(
'connected'=> $connected,
'login'=> $this->tabInfoUser['login'],
'id'=> $this->tabInfoUser['id'],
'idClient'=> $this->tabInfoUser['idClient'],
'email'=> $this->tabInfoUser['email'],
'typeCompte'=> $this->tabInfoUser['typeCompte'],
'filtre_ip'=> $this->tabInfoUser['filtre_ip'],
'ipPasserelle'=> $this->tabInfoUser['ipConnexion'],
'ipConnexion'=> $ipUtilisateur,
'civilite'=> $this->tabInfoUser['civilite'],
'nom'=> $this->tabInfoUser['nom'],
'prenom'=> $this->tabInfoUser['prenom'],
'raisonSociale'=> $this->tabInfoUser['raisonSociale'],
'siret'=> $this->tabInfoUser['siret'],
'adrNum'=> $this->tabInfoUser['adrNum'],
'adrIndRep'=> $this->tabInfoUser['adrIndRep'],
'adrTypeVoie'=> $this->tabInfoUser['adrTypeVoie'],
'adrLibVoie'=> $this->tabInfoUser['adrLibVoie'],
'adrCp'=> $this->tabInfoUser['adrCp'],
'adrVille'=> $this->tabInfoUser['adrVille'],
'adrComp'=> $this->tabInfoUser['adrComp'],
'tel'=> $this->tabInfoUser['tel'],
'fax'=> $this->tabInfoUser['fax'],
'mobile'=> $this->tabInfoUser['mobile'],
'pref'=> $this->tabInfoUser['pref'],
'profil'=> $this->tabInfoUser['profil'],
'dateInscription'=> $this->tabInfoUser['dateInscription'],
'dateValidation'=> $this->tabInfoUser['dateValidation'],
'nombreConnexions'=> $this->tabInfoUser['nombreConnexions'],
'dateDerniereConnexion'=> $this->tabInfoUser['dateDerniereConnexion'],
'droits'=> $this->tabInfoUser['droits'],
'droitsClients'=> $this->tabInfoUser['droitsClients'],
'timeout'=> $this->tabInfoUser['timeout'],
'nbReponses'=> $this->tabInfoUser['nbReponses'],
'formatMail'=> $this->tabInfoUser['formatMail'],
'reference'=> $this->tabInfoUser['referenceParDefaut'],
'dateDebutCompte'=> $this->tabInfoUser['dateDebutCompte'],
'dateFinCompte'=> $this->tabInfoUser['dateFinCompte'],
'maxFicheId'=> $this->tabInfoUser['maxFicheId'],
'typeScore'=> $this->tabInfoUser['typeScore'],
);
//debugLog('I',"getInfosLogin fin ".print_r($rep,true),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
}
$result = new InfosLogin();
$result = arrayToClass($rep, 'InfosLogin');
$output = new InfosLoginReturn();
$output->error = $error;
$output->result = $result;
return $output;
}
/**
* Obtention automatique d'un nouveau login pour un client
* @param string $login
* @return NextLoginReturn
*/
public function getNextLogin( $login )
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
$error = new ErrorType();
if ($this->tabInfoUser['profil']=='Administrateur' ||
$this->tabInfoUser['profil']=='SuperAdministrateur')
{
/** Un administrateur veut créer un nouveau login **/
$rep = $iDbCrm->select('utilisateurs u, clients c', 'u.idClient, c.racineLogin, c.droits', "u.login='$login' AND u.idClient=c.id");
$racine = $rep[0]['racineLogin'];
$idClient = $rep[0]['idClient'];
$droitsClients = $rep[0]['droits'];
$rep = $iDbCrm->select('utilisateurs', 'login, length(login) as taille', "login like '$racine%' group by login order by taille desc, login desc LIMIT 0,1");
if (count($rep)==0) {
$racine.='1';
}
else
{
$last_i = preg_replace("/\D/", '',$rep[0]['login'])*1;
$racine.= $last_i+1;
}
$result = new NextLoginResult();
$result->racine = $racine;
$result->idClient = $idClient;
$result->droitsClients = $droitsClients;
}
else
{
$error->errnum = 0;
$error->errmsg = 'Acces non authorisé!';
}
$output = new NextLoginReturn();
return $output;
}
/**
* Enter description here ...
* @param string $siret
* @param string $type
* @param string $codeInsee
* @return ListeCompetencesReturn
*/
public function getListeCompetences($siret, $type, $codeInsee)
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
$error = new ErrorType();
$type = strtolower($type);
debugLog('I',"Liste des compétences $type demandée pour la commune $codeInsee",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$tabRet = array();
$iBodacc = new MBodacc();
$cp=$codeInsee*1;
$dep=false;
if (substr($codeInsee,0,2)=='2A' || substr($codeInsee,0,2)=='2B')
{
$dep=20; $cp=20000+(substr($codeInsee,2,3))*1;
}
elseif ($cp>0 && $cp<100) $dep=$cp;
elseif ($cp>970 && $cp<977) $dep=$cp;
elseif ($cp>999 && $cp<10000) $dep='0'.substr($cp,0,1);
elseif ($cp>=10000 && $cp<96000) $dep=substr($cp,0,2);
elseif ($cp>=99000) $dep=substr($cp,0,2);
elseif ($cp>=98000) $dep=substr($cp,0,3);
elseif ($cp>=97100 && $cp<97700) $dep=substr($cp,0,3);
if ($type=='pre')
{
$iDb = new WDB('jo');
$tabTmp2 = $iDb->select('villes', 'DEP, COM, AR, CT', 'codeInsee='.$codeInsee, false, MYSQL_ASSOC);
$arrond = $tabTmp2[0]['AR'];
unset($iDb);
$iDb = new WDB('insee');
$tabTmp2 = $iDb->select('insee_tabArrond', 'CHEFLIEU, ARTMAJ, NCC', "DEP='$dep' AND AR='$arrond'", false, MYSQL_ASSOC);
$nomSousPref = trim(strtr($tabTmp2[0]['ARTMAJ'],array('('=>'',')'=>'',' '=>'', "'"=>'')).' '.$tabTmp2[0]['NCC']);
unset($iDb);
$tabTmp = $iBodacc->getTribunauxParDep($dep);
foreach ($tabTmp as $i=>$tribunal)
{
if ($tribunal['triType']=='A' || $tribunal['triType']=='B')
{
$pref = levenshtein($tribunal['triNom'], 'PREFECTURE DE '.$nomSousPref);
$spref = levenshtein($tribunal['triNom'], 'SOUS PREFECTURE DE '.$nomSousPref);
if ($tribunal['triType']=='B' && ($pref>7 || $spref>5)) continue;
$competence = new Competence();
$competence = arrayToClass(array(
'Id' => $tribunal['triId'],
'IdSup' => $tribunal['triIdSup'],
'Code' => $tribunal['triCode'],
'Type' => $tribunal['triType'].$typeP,
'Nom' => strtoupper($tribunal['triNom']),
'Siret' => $tribunal['triSiret'],
'Adr' => strtoupper(preg_replace('/ +/',' ',$tribunal['triAdrNum'].' '.$tribunal['triAdrIndRep'].' '.
$tribunal['triAdrTypeVoie'].' '.$tribunal['triAdrVoie'])),
'AdrComp' => strtoupper($tribunal['triAdrComp']),
'CP' => $tribunal['triCP'],
'Ville' => strtoupper($tribunal['triVille']),
'CodeInsee' => $tribunal['CodeInsee'],
'Tel' => $tribunal['triTel'],
'Fax' => $tribunal['triFax'],
'Web' => $tribunal['triWeb'],
'Mail' => $tribunal['triMail'],
'Statut' => $tribunal['triStatut'],
'DateCessation' => $tribunal['triDateCessation'],
'Remarque' => $tribunal['triCommentaire'],
), 'Competence');
$tabRet[$i] = $competence;
}
}
}
elseif ($type=='jal')
{
$tabTmp = $iBodacc->getJALparDep($dep);
foreach ($tabTmp as $i=>$comp)
{
$infos='';
if (trim($comp['parution'])<>'') $infos.='Parution '.$comp['parution'].'. ';
if (trim($comp['aboAnnuel'])>0) $infos.='Abonnement Annuel : '.$comp['aboAnnuel'].' euros. ';
if (trim($comp['infos'])<>'') $infos.=$comp['infos'];
$competence = new Competence();
$competence = arrayToClass(array(
'Id' => 9000+$comp['id']*1,
'IdSup' => 0,
'Code' => '',
'Type' => '',
'Nom' => strtoupper($comp['nomJal']),
'Siret' => '',
'Adr' => strtoupper($comp['adresse']),
'AdrComp' => '',
'CP' => $comp['cp'],
'Ville' => strtoupper($comp['ville']),
'CodeInsee' => '',
'Tel' => $comp['tel'],
'Fax' => $comp['fax'],
'Web' => $comp['siteWeb'],
'Mail' => $comp['email'],
'Statut' => 'Actif',
'DateCessation' => '',
'Remarque' => trim($infos),
), 'Competence');
$tabRet[$i] = $competence;
}
}
elseif ($type=='tri' || $type=='adm' || $type=='hui')
{
$tabTmp = $iBodacc->getTribunauxParCommune($codeInsee);
foreach ($tabTmp as $i=>$tribunal)
{
if (//$tribunal['triType']=='C' ||
$tribunal['triType']=='G'// ||
/*$tribunal['triType']=='I'*/) {
$idCA=$tribunal['triIdSup'];
$codeTGI=$tribunal['triCode'];
$code=strtoupper(substr($tribunal['triCode'],0,3));
}
debugLog('D',"Liste des compétences $type demandée pour la commune $codeInsee ($dep) : ".
"Type=".$tribunal['triType'].', '.
"Code=".$tribunal['$codeTGI'],__LINE__,__FILE__, __FUNCTION__, __CLASS__);
if ($tribunal['triType']<>'E' && $tribunal['triType']<>'O' &&
$tribunal['triType']<>'T' && $tribunal['triType']<>'R' &&
$tribunal['triType']<>'N' && $tribunal['triType']<>'U' &&
$tribunal['triType']<>'Z')
{
$competence = new Competence();
$competence = arrayToClass(array(
'Id' => $tribunal['triId'],
'IdSup' => $tribunal['triIdSup'],
'Code' => $tribunal['triCode'],
'Type' => $tribunal['triType'],
'Nom' => strtoupper($tribunal['triNom']),
'Siret' => $tribunal['triSiret'],
'Adr' => strtoupper(preg_replace('/ +/',' ',$tribunal['triAdrNum'].' '.$tribunal['triAdrIndRep'].' '.
$tribunal['triAdrTypeVoie'].' '.$tribunal['triAdrVoie'])),
'AdrComp' => strtoupper($tribunal['triAdrComp']),
'CP' => $tribunal['triCP'],
'Ville' => strtoupper($tribunal['triVille']),
'CodeInsee' => $tribunal['CodeInsee'],
'Tel' => $tribunal['triTel'],
'Fax' => $tribunal['triFax'],
'Web' => $tribunal['triWeb'],
'Mail' => $tribunal['triMail'],
'Statut' => $tribunal['triStatut'],
'DateCessation' => $tribunal['triDateCessation'],
'Remarque' => $tribunal['triCommentaire'],
), 'Competence');
if ($tribunal['triNumGreffe']*1>0)
{
$competence->IdentifiantGreffe = $tribunal['triNumGreffe'];
}
$tabRet[$i] = $competence;
}
}
}
if ($type=='adm')
{
$tabTmp=$this->iInsee->getMandataires(array($idCA), false);
$tabRet = array();
$nbAff=0;
foreach ($tabTmp as $i=>$tribunal)
{ /** @todo A revoir Debut **/
if (stripos($tribunal['tribunal'], $code)!==false ||
stripos($tribunal['tribunal'], 'SAINT')!==false)
{
$competence = new Competence();
$competence = arrayToClass(array(
'Id' => $tribunal['id'],
'IdSup' => $tribunal['sirenGrp'],
'Code' => $tribunal['tribunal'].'/'.$code,
'Type' => $tribunal['type'],
'Nom' => $tribunal['Nom'].' '.$tribunal['Prenom'],
'Siret' => $tribunal['sirenMand'],
'Adr' => strtoupper($tribunal['adresse']),
'AdrComp' => strtoupper($tribunal['adresseComp']),
'CP' => $tribunal['cp'],
'Ville' => strtoupper($tribunal['ville']),
//'CodeInsee'=>$tribunal['CodeInsee'],
'Tel' => $tribunal['tel'],
'Fax' => $tribunal['fax'],
'Web' => $tribunal['web'],
'Mail' => $tribunal['email'],
'Statut' => $tribunal['Statut'],
//'DateCessation'=>$tribunal['triDateCessation'],
'Remarque' => $tribunal['contact'],
), 'Competence');//,,,,Prenom,,,Statut,,,cp,ville,tel,fax,email,web,contact
$tabRet[$i] = $competence;
$nbAff++;
}
}
if ($nbAff==0)
{
foreach ($tabTmp as $i=>$tribunal)
{
$competence = new Competence();
$competence = arrayToClass(array(
'Id' => $tribunal['id'],
'IdSup' => $tribunal['sirenGrp'],
'Code' => $tribunal['tribunal'].'/'.$code,
'Type' => $tribunal['type'],
'Nom' => $tribunal['Nom'].' '.$tribunal['Prenom'],
'Siret' => $tribunal['sirenMand'],
'Adr' => strtoupper($tribunal['adresse']),
'AdrComp' => strtoupper($tribunal['adresseComp']),
'CP' => $tribunal['cp'],
'Ville' => strtoupper($tribunal['ville']),
//'CodeInsee'=>$tribunal['CodeInsee'],
'Tel' => $tribunal['tel'],
'Fax' => $tribunal['fax'],
'Web' => $tribunal['web'],
'Mail' => $tribunal['email'],
'Statut' => $tribunal['Statut'],
//'DateCessation'=>$tribunal['triDateCessation'],
'Remarque' => $tribunal['contact'],
), 'Competence');//,,,,Prenom,,,Statut,,,cp,ville,tel,fax,email,web,contact
$tabRet[$i] = $competence;
}
}/** @todo A revoir Fin : Lier correctement les mandataires à un TI principal **/
}
elseif ($type=='hui')
{
$tabTmp = $this->iInsee->getHuissiers(array($codeTGI), false);
$tabRet = array();
$nbAff = 0;
foreach ($tabTmp as $i=>$tribunal)
{
$adr=$this->iInsee->structureVoie($tribunal['adresse']);
$competence = new Competence();
$competence = arrayToClass(array(
'Id' => $tribunal['id'],
'IdSup' => $tribunal['sirenGrp'],
'Code' => $tribunal['tribunal'].'/'.$code,
'Type' => $tribunal['type'],
'Nom' => $tribunal['Nom'].' '.$tribunal['Prenom'],
'Siret' => $tribunal['sirenMand'],
'Adr' => strtoupper($adr['num'].' '.$adr['adr_btq'].' '.
$adr['typeVoie'].' '.$adr['libVoie']),
'AdrComp' => strtoupper($tribunal['adresseComp']),
'CP' => $adr['cp'],
'Ville' => strtoupper($tribunal['ville']),
//'CodeInsee'=>$tribunal['CodeInsee'],
'Tel' => $tribunal['tel'],
'Fax' => $tribunal['fax'],
'Web' => $tribunal['web'],
'Mail' => $tribunal['email'],
'Statut' => $tribunal['Statut'],
//'DateCessation'=>$tribunal['triDateCessation'],
'Remarque' => strtr($tribunal['contact'],
array( '<br/>'=>', ', '<br>'=>', ',
'<br />'=>', ',
)),
), 'Competence');
$tabRet[$i] = $competence;
}
$nbComp = count($tabTmp);
debugLog('I',"$nbComp compétences $type trouvées pour le tribunal $codeTGI",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
}
elseif ($type=='cfe')
{
$tabTmp = $iBodacc->getTribunauxParCommune($codeInsee);
foreach ($tabTmp as $i=>$tribunal)
{
if ($tribunal['triType']=='C' || $tribunal['triType']=='O' ||
$tribunal['triType']=='T' || $tribunal['triType']=='R' ||
$tribunal['triType']=='N' || $tribunal['triType']=='U' ||
$tribunal['triType']=='Z')
{
if (strlen($tribunal['triCommentaire'])==32 &&
strpos($tribunal['triCommentaire'], ' ')===false)
$remarque='';
else $remarque=prepareString($tribunal['triCommentaire']);
$competence = new Competence();
$competence = arrayToClass(array(
'Id' => $tribunal['triId'],
'IdSup' => $tribunal['triIdSup'],
'Code' => $tribunal['triCode'],
'Type' => $tribunal['triType'],
'Nom' => strtoupper($tribunal['triNom']),
'Siret' => $tribunal['triSiret'],
'Adr' => strtoupper(preg_replace('/ +/',' ',$tribunal['triAdrNum'].' '.$tribunal['triAdrIndRep'].' '.
$tribunal['triAdrTypeVoie'].' '.$tribunal['triAdrVoie'])),
'AdrComp' => strtoupper($tribunal['triAdrComp']),
'CP' => $tribunal['triCP'],
'Ville' => strtoupper($tribunal['triVille']),
'CodeInsee' => $tribunal['CodeInsee'],
'Tel' => $tribunal['triTel'],
'Fax' => $tribunal['triFax'],
'Web' => $tribunal['triWeb'],
'Mail' => $tribunal['triMail'],
'Statut' => $tribunal['triStatut'],
'DateCessation' => $tribunal['triDateCessation'],
'Remarque' => $remarque,
), 'Competence');
$tabRet[$i] = $competence;
}
}
}
wsLog('competences',$siret,$type.'/'.$codeInsee);
$result = new ListeCompetencesResult();
$result->nbReponses = count($tabRet);
$result->liste = $tabRet;
$output = new ListeCompetencesReturn();
$output->error = $error;
$output->result = $result;
/*Zend_Registry::get('WsLogger')
->info(__FUNCTION__.' - '.print_r($output, 1));*/
return $output;
}
/**
* Retourne la liste des banques connues pour une entreprise
* @param string $siren Siren de l'entreprise
* @return BanquesReturn
**/
public function getBanques($siren)
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
$error = new ErrorType();
$iDb = new WDB('sdv1');
$tabRet = array();
debugLog('I',"Liste des banques demandée pour siren $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
if ($siren*1>1000)
{
$res=$iDb->select('banques', 'codeBanque, codeGuichet, libBanqueGuichet, precis, dateSource*1 AS dateSource', "siren=$siren", false, MYSQL_ASSOC);
$tmp=$iDb->select('fedRib', "codeBanque, codeGuichet, CONCAT(libBanque,' ',libGuichet) AS libBanqueGuichet, 0 AS precis, IF (dateInfo='0000-00-00', dateDispo*1, dateInfo*1) AS dateSource", "siren=$siren", false, MYSQL_ASSOC);
$res=array_merge($res, $tmp);
foreach ($res as $tabBanque)
{
$dateSource=$tabBanque['dateSource'];
$codBanque=$tabBanque['codeBanque'];
$codGuichet=$tabBanque['codeGuichet'];
$libBanque=trim($tabBanque['libBanqueGuichet']);
$found=false;
$adrBanque1=$adrBanque2=$adrBanqueCP=$adrBanqueVille='';
if ($codBanque>0 && $codGuichet>0 &&
$dateSource>(date('Y')-4)*10000+101 &&
$dateSource<date('Ymd'))
{
$tmp=$iDb->select('insee.BDF_Etabs b, insee.BDF_Guichets g', 'g.bdfFibCodeEtab AS banque, g.bdfFibCodeGuichet AS guichet, b.bdfFibDenom40 AS nomBanque, b.bdfFibDenom10 AS sigleBanque, g.bdfFibDenom20 AS nomGuichet, g.bdfFibAdresse1 AS adresse1, g.bdfFibAdresse2 AS adresse2, g.bdfFibAdresse3 AS adresse3, g.CP, g.Ville', "g.bdfFibCodeEtab=$codBanque AND g.bdfFibCodeGuichet=$codGuichet AND b.bdfFibCodeEtab=g.bdfFibCodeEtab", false, MYSQL_ASSOC);
if (isset($tmp[0]))
{
$libBanque=trim($tmp[0]['nomBanque'].' '.$tmp[0]['nomGuichet']);
$adrBanque1=$tmp[0]['adresse1'];
$adrBanque2=trim($tmp[0]['adresse2'].' '.$tmp[0]['adresse3']);
$adrBanqueCP=$tmp[0]['CP'];
$adrBanqueVille=$tmp[0]['Ville'];
$found=true;
};
}
if (!$found && $codBanque>0 &&
$dateSource>(date('Y')-4)*10000+101 &&
$dateSource<date('Ymd'))
{
$tmp=$iDb->select('insee.BDF_Etabs', "bdfFibCodeEtab AS banque, '' AS guichet, bdfFibDenom40 AS nomBanque, '' AS nomGuichet, '' AS adresse1, '' AS adresse2, '' AS adresse3, '' AS CP, '' AS Ville", "bdfFibCodeEtab=$codBanque", false, MYSQL_ASSOC);
if (isset($tmp[0]))
{
$libBanque=trim($tmp[0]['nomBanque'].' '.$tmp[0]['nomGuichet']);
$adrBanque1=$tmp[0]['adresse1'];
$adrBanque2=trim($tmp[0]['adresse2'].' '.$tmp[0]['adresse3']);
$adrBanqueCP=$tmp[0]['CP'];
$adrBanqueVille=$tmp[0]['Ville'];
} else continue;
} else continue;
$banque = new Banque();
$banque->codeBanque = $codBanque;
$banque->codeGuichet = $codGuichet;
$banque->libBanque = $libBanque;
$banque->adresse1 = $adrBanque1;
$banque->adresse2 = $adrBanque2;
$banque->ville = $adrBanqueCP;
$banque->cp = $adrBanqueCP;
$banque->ville = $adrBanqueVille;
$tabRet[] = $banque;
}
}
else
{
$error->errnum = 75454698;
$error->errmsg = 'Siren invalide';
}
debugLog('I',"Liste des banques pour siren $siren : ".count($tabRet).' banques',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
if (count($tabRet)==0)
{
$error->errnum = 256454;
$error->errmsg = 'Aucune relation bancaire en base';
}
$output = new BanquesReturn();
$output->error = $error;
$output->result = $tabRet;
return $output;
}
/**
*
* Retourne la liste des conventions
* @param string $siren
* @return ListeConventionsReturn
*/
public function getListeConventions($siren)
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
$error = new ErrorType();
$tabRet=array();
debugLog('I',"Liste des conventions demandée pour le siren $siren",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
if (strlen($siren)<>9)
{
debugLog('W', "Siren/Siret $siren incorrect", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
$error->errnum = 102;
$error->errmsg = 'Siren Siret inexistant';
}
elseif ($siren*1==0)
{
debugLog('W', "Siren $siren inexistant", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
$error->errnum = 102;
$error->errmsg = 'Siren inexistant';
}
else
{
$tabIdentite = $this->iInsee->getIdentiteEntreprise($siren);
if (empty($tabIdentite) && isset($tabIdentite['erreur']) &&
$tabIdentite['erreur']<>'')
{
debugLog('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 MSolvabilite($siren, $naf, $trancheEffectif, $effectif, $tabIdentite['CP'], $fj, $tabIdentite['Capital'],
$tabIdentite['CapitalDev'], $tabIdentite['DateCreaEn'], $tabIdentite['DateCreaEt']);//, $tabIdentite['Singularite']);
$noteStructure = $isolv->getSolvabilite();
$naf4 = $isolv->getNaf4($naf);
$tabTmp = $this->iInsee->listeConventions($naf4, $tabIdentite['Dept']);
foreach ($tabTmp as $i=>$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[$i] = $convention;
}
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)
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
$iBodacc = new 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)
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
$error = new ErrorType();
$annonceCollecte = new AnnonceCollecte();
$siren = substr(''.$siret,0,9)*1;
if ($this->tabInfoUser['idClient']<>1)
{
$error->errnum = 0;
$error->errmsg = 'Code Client Incorrect';
}
else
{
$iDb = new WDB();
debugLog('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('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'];
$tabEven = array();
foreach ( $ann['typeEven'] as $code => $even )
{
$annonceEvenement = new AnnonceEvenement();
$annonceEvenement->codeEven = $code;
$annonceEvenement->LibEven = $even;
$tabEven[] = $annonceEvenement;
}
foreach ( explode(';',$ann['strEven']) as $code => $even )
{
$annonceEvenement = new AnnonceEvenement();
$annonceEvenement->codeEven = $code;
$annonceEvenement->LibEven = $even;
$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'];
debugLog('I',"Lecture de l'annonce collectée n°$idAnn ($siret) : ".$ann['raisonSociale'],__LINE__,__FILE__, __FUNCTION__, __CLASS__);
}
}
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='')
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
$error = new ErrorType();
if (empty($codeIsoDevise)) $codeIsoDevise = '';
debugLog('I',"Liste des devises ou devise $codeIsoDevise demandée",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$tabTmp = $this->iInsee->getDevises($codeIsoDevise);
$tabRet = array();
foreach ($tabTmp as $i=>$devise)
{
$devise = new Devise();
$devise->devIso = $i;
$devise->devNom = $devise;
$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)
{
//Authentification
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
//Initialisation
$error = new ErrorType();
$iDb = new WDB('sdv1');
if ($devise) $strDevise=" AND c.devise='$devise' ";
else $strDevise='';
$tabRet = array();
$res = $iDb->select('devise_cours c, 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;
}
}