2834 lines
88 KiB
PHP
2834 lines
88 KiB
PHP
<?php
|
|
require_once __DIR__ . '/Types.php';
|
|
|
|
class Saisie extends Scores_Ws_Server
|
|
{
|
|
/**
|
|
* 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 = utf8_encode($mand);
|
|
$tabRet[] = $mandataire;
|
|
}
|
|
$output = new SearchMandatairesReturn();
|
|
$output->result = $tabRet;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Enregistrement des informations saisie manuellement
|
|
* @param string $siret
|
|
* @param int $idEntreprise
|
|
* @param string $infos
|
|
* @return SetInfosEntrepReturn
|
|
*/
|
|
public function setInfosEntrep( $siret, $idEntreprise, $infos )
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Initialisation
|
|
$tabRet = array();
|
|
$iBodacc = new Metier_Bodacc_MBodacc();
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$result = false;
|
|
|
|
if (!$this->checkEdition()) {
|
|
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code Client Incorrect';
|
|
|
|
} else {
|
|
$siren = substr($siret,0,9);
|
|
$nic = substr($siret,9,5);
|
|
|
|
$iDb = new Metier_Util_Db();
|
|
|
|
$tabInfos = json_decode($infos, true);
|
|
|
|
$tabIdentite = $tabInfos['identite'];
|
|
$tabJugement = $tabInfos['jugement'];
|
|
$tabActio = $tabInfos['actionnaire'];
|
|
$tabParti = $tabInfos['participation'];
|
|
$tabScores = $tabInfos['score'];
|
|
|
|
//Valider le code Isin
|
|
if (strlen(trim($tabIdentite['isin']))) {
|
|
$iBourse = new Metier_Partenaires_MBourse();
|
|
if (!$iBourse->isIsin($tabIdentite['isin'])) {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code Isin incorrect.';
|
|
$output = new SetInfosEntrepReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
// Mise à jour de l'identité
|
|
if (trim(strtolower($tabIdentite['web']))=='http://'){
|
|
$web = '';
|
|
} else {
|
|
$web = trim($tabIdentite['web']);
|
|
}
|
|
$tabUpdate = array(
|
|
'isin' => trim($tabIdentite['isin']),
|
|
'tel' => trim($tabIdentite['tel']),
|
|
'fax' => trim($tabIdentite['fax']),
|
|
'web' => $web,
|
|
'mail' => trim($tabIdentite['mail']),
|
|
'activite' => stripslashes(trim($tabIdentite['activite'])),
|
|
'sirenDoublon' => substr(str_replace(' ','',strtr($tabIdentite['sirenDoublon'], '"\'./- ,\*#()',' ')),0,9),
|
|
'waldec' => trim(str_replace(' ','',strtr($tabIdentite['waldec'], '"\'./- ,\*#()',' '))),
|
|
);
|
|
|
|
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
|
$sql = $db->select()->from('infos_entrep', array('siren'), 'jo')->where('siren=?',$siren);
|
|
$result = $db->fetchAll($sql);
|
|
if (count($result) == 0 ) {
|
|
try {
|
|
$isInserted = $db->insert('jo.infos_entrep', array_merge(array('siren'=>$siren), $tabUpdate));
|
|
} catch(Zend_Db_Exception $e) {
|
|
file_put_contents('insert.log', "INSERT = ".$e->getMessage());
|
|
}
|
|
} else {
|
|
try {
|
|
$isUpdated = $db->update('jo.infos_entrep', $tabUpdate, "siren=$siren");
|
|
} catch(Zend_Db_Exception $e) {
|
|
file_put_contents('update.log', "INSERT = ".$e->getMessage());
|
|
}
|
|
}
|
|
// Fin mise à jour identité
|
|
|
|
// Opposition INSEE
|
|
if ( $tabIdentite['moisOppositionInsee']>0 &&
|
|
$tabIdentite['moisOppositionInsee']<=(date('Ym')*1) ){
|
|
|
|
$iDb2 = new Metier_Util_Db();
|
|
if ( !$iDb2->insert('insee.insee_nondiff', array('siren'=>$siren, 'insEVE'=>795, 'mois'=>$tabIdentite['moisOppositionInsee'])) ){
|
|
if ( $iDb2->getLastErrorNum()<>1062 ) {}
|
|
}
|
|
|
|
}
|
|
// Fin opposition INSEE
|
|
|
|
// Refus d'inscription au RCS
|
|
if (isset($tabIdentite['moisRefusRCS']) && $tabIdentite['moisRefusRCS']>0
|
|
&& $tabIdentite['moisRefusRCS']<=(date('Ym')*1)) {
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$entrep = $iInsee->getIdentiteLight($siren);
|
|
if ($nic<10) $nic=$entrep['Nic'];
|
|
$cj1=substr($entrep['FJ'],0,1);
|
|
$iDb2 = new Metier_Util_Db();
|
|
/** Insertion dans la tables des exclusions **/
|
|
$tabInsert = array(
|
|
'siren' => $siren,
|
|
'nic' => $nic,
|
|
'idSaisie' => $this->User->id,
|
|
'cj1' => $cj1,
|
|
'insEVE' => 'RCS',
|
|
'mois' => $tabIdentite['moisRefusRCS'],
|
|
);
|
|
if (!$iDb2->insert('insee.insee_nondiff', $tabInsert))
|
|
if ($iDb2->getLastErrorNum()<>1062) {}
|
|
|
|
/** Insertion dans la tables des évènements **/
|
|
$tabInsert = array(
|
|
'insSIREN' => $siren,
|
|
'siretValide' => $iInsee->valideSiren($siren,$nic),
|
|
'insNIC' => $nic,
|
|
'insEVE' => 'RCS',
|
|
'insDATEVE' => $tabIdentite['moisRefusRCS'].'28',
|
|
'insDATEMAJ' => date('YmdHis'),
|
|
'idFlux' => date('Ymd'));
|
|
if (!$iDb2->insert('insee.insee_even', $tabInsert)) {}
|
|
}
|
|
// Fin refus d'inscription au RCS
|
|
|
|
// Domiciliataire
|
|
if (!empty($tabIdentite['domiciliataire']) && $siren>1000) {
|
|
if ($tabIdentite['domiciliataire']=='oui' || $tabIdentite['domiciliataire']=='non') {
|
|
// L'entreprise et ces établissements seront mis à jour automatiquement ce soir
|
|
$iDb->query("INSERT IGNORE INTO jo.tabAdrDom (siren,nic,siege, etActif, nom, sigle, enseigne, adrNum, adrBtq, adrTypVoie, adrLibVoie, ville, cp, depComEt, adrComp, cj, apen,apet, dateInsert)
|
|
SELECT siren, nic, siege, actif AS etActif, raisonSociale AS nom, sigle, enseigne, adr_num as adrNum, adr_btq AS adrBtq, adr_typeVoie AS adrTypVoie, adr_libVoie AS adrLibVoie, adr_ville AS ville, adr_cp AS cp, CONCAT(adr_dep,adr_com) AS depComEt, adr_comp AS adrComp, cj, ape_entrep AS apen, ape_etab AS apet, DATE(NOW()) as dateInsert
|
|
FROM jo.etablissements WHERE siren=$siren;", false);
|
|
}
|
|
// Si demande de suppression, on force l'indicateur ""
|
|
if ($tabIdentite['domiciliataire']=='non') {
|
|
$tabUpdate=array('pasEntrepDom'=>1);
|
|
$iDb->update('jo.tabAdrDom', $tabUpdate, "siren=$siren");
|
|
}
|
|
}
|
|
// Fin domiciliataire
|
|
|
|
// Insertion des scores
|
|
$tabUpdate = array();
|
|
$setScore = false;
|
|
if ( $tabScores['encours']!='' || $tabScores['encours']!=null ){
|
|
$tabUpdate['encours'] = $tabScores['encours'];
|
|
$setScore = true;
|
|
}
|
|
if ( $tabScores['scoreSolv']!='' ){
|
|
$tabUpdate['scoreSolv'] = $tabScores['scoreSolv'];
|
|
$setScore = true;
|
|
}
|
|
if ( $tabScores['scoreDir']!='' ){
|
|
$tabUpdate['scoreDir'] = $tabScores['scoreDir'];
|
|
$setScore = true;
|
|
}
|
|
if ( $tabScores['scoreConf']!='' ){
|
|
$tabUpdate['scoreConf'] = $tabScores['scoreConf'];
|
|
$setScore = true;
|
|
}
|
|
if ( $setScore ){
|
|
// Mise à jour des Cute Offs
|
|
if ( !$iDb->update('jo.scores_cutoff', $tabUpdate, "siren=$siren") ){
|
|
if ( !$iDb->insert('jo.scores_cutoff', array_merge(array(
|
|
'siren' => $siren,
|
|
'dateInsert' => date('Ymd') ), $tabUpdate)) ){
|
|
//
|
|
}
|
|
}
|
|
}
|
|
// Fin insertion des scores
|
|
|
|
// Insertion du jugement
|
|
$tabEven = $tabJugement['even'];
|
|
$nic = $tabJugement['nic']*1;
|
|
$entrep = $iInsee->getIdentiteLight($siren, $nic);
|
|
if ( $nic>0 && $tabEven[0]==6700 && $entrep['Siege']==0 ){
|
|
// Radiation d'un établissement
|
|
$tabEven[0] = 6600;
|
|
}
|
|
|
|
if ( count($tabEven)>0 ){
|
|
$idAdmin = str_replace('m','',trim($tabJugement['admin']));
|
|
$idMand = str_replace('m','',trim($tabJugement['mand']));
|
|
$idOppo = str_replace('m','',trim($tabJugement['oppo']));
|
|
|
|
$tabSource=explode('_',$tabJugement['source']);
|
|
$source=@$tabSource[0];
|
|
$numJal=@$tabSource[1];
|
|
|
|
$dateSource=Metier_Util_Date::dateT('d/m/Y', 'Ymd', trim($tabJugement['dateParution']))*1;
|
|
if ($dateSource<20000101)
|
|
$dateSource=date('YmdHis');
|
|
|
|
$montant=trim(preg_replace('/[^0-9]/', '', $tabJugement['montant']))*1;
|
|
$actionsMt=trim(preg_replace('/[^0-9]/', '', $tabJugement['actionsMt']))*1;
|
|
$actionsNb=trim(preg_replace('/[^0-9]/', '', $tabJugement['actionsNb']))*1;
|
|
if ($montant>0 && ($actionsNb>0 || $actionsMt>0)) {
|
|
if ($actionsNb>0) $actionsMt=$montant/$actionsNb;
|
|
elseif ($actionsMt>0) $actionsNb=$montant/$actionsMt;
|
|
}
|
|
|
|
//@todo : ça ne va pas marcher ici
|
|
$strDir='';
|
|
|
|
if (count($tabJugement['nouvDir'])>0) {
|
|
foreach( $tabJugement['nouvDir'] as $dir ){
|
|
if ( intval($dir['Fonc'])>0 ){
|
|
$strDir.= $iBodacc->getFctDir($dir['Fonc']).' : '.$dir['Genre'].' '.
|
|
ucwords(strtolower($dir['Pre'])).' '.strtoupper($dir['Nom']);
|
|
if (!empty($dir['Dom'])) {
|
|
$strDir.= ', domicilié à '.$dir['Dom'].'. ';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( trim($tabJugement['nouvAdrCp'])<>'' ){
|
|
$strAdr = stripslashes(trim($tabJugement['nouvAdr']).', '.
|
|
trim($tabJugement['nouvAdrCp']).' '.
|
|
trim($tabJugement['nouvAdrVille']));
|
|
} else {
|
|
$strAdr='';
|
|
}
|
|
|
|
if (count($tabEven)>1){
|
|
$strEven = implode(';',array_slice($tabEven, 1));
|
|
} else {
|
|
$strEven = '';
|
|
}
|
|
|
|
$tabUpdate = array(
|
|
'strEven' => $strEven,
|
|
'sirenValide' => $iInsee->valideSiren($siren),
|
|
'dateCessationPaiement' => empty($tabJugement['datePaie']) ? '' :
|
|
Metier_Util_Date::dateT('d/m/Y', 'Y-m-d', trim($tabJugement['datePaie'])),
|
|
'dateEffetFinP' => empty($tabJugement['dateFinPeriode']) ? '' :
|
|
Metier_Util_Date::dateT('d/m/Y', 'Y-m-d', trim($tabJugement['dateFinPeriode'])),
|
|
'tribunal' => trim($tabJugement['tribunal']),
|
|
'montant' => $montant,
|
|
'actionsNb' => $actionsNb,
|
|
'inter1type' => 'A',
|
|
'inter1id' => $idAdmin,
|
|
'inter1nom' => $iInsee->getMandatairesParId($idAdmin),
|
|
'inter2type' => 'M',
|
|
'inter2id' => $idMand,
|
|
'inter2nom' => $iInsee->getMandatairesParId($idMand),
|
|
'inter3type' => 'O',
|
|
'inter3id' => $idOppo,
|
|
'inter3nom' => $iInsee->getMandatairesParId($idOppo),
|
|
'complement' => stripslashes(trim($tabJugement['comp'])),
|
|
'nouvActivite' => stripslashes(trim($tabJugement['nouvActivite'])),
|
|
'nouvDir' => stripslashes(trim($strDir)),
|
|
'nouvAdr' => $strAdr,
|
|
'nouvFJ' => trim($tabJugement['nouvFJ']),
|
|
'raisonSociale' => $entrep['Nom'],
|
|
'adresse' => $entrep['Adresse'],
|
|
'codePostal' => $entrep['CP'],
|
|
'ville' => $entrep['Ville'],
|
|
'source' => $source,
|
|
'idSaisie' => $this->User->id,
|
|
'parutionIdJal' => $numJal,
|
|
'parutionNum' => $tabJugement['numParution'],
|
|
);
|
|
$dateJuge = Metier_Util_Date::dateT('d/m/Y','Y-m-d',trim($tabJugement['dateJuge']));
|
|
$tabInsert = array_merge( $tabUpdate, array(
|
|
'siren' => $siren,
|
|
'dateJugement' => $dateJuge,
|
|
'typeEven' => $tabEven[0],
|
|
'dateSource' => $dateSource,
|
|
));
|
|
if ( !$iDb->insert('jo.annonces', array_merge($tabInsert,array('dateInsert'=>date('YmdHis'))), true) ){
|
|
if ( !$iDb->update('jo.annonces', $tabUpdate, "siren=$siren AND dateJugement='$dateJuge' AND typeEven=".$tabEven[0], true)){
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Mise a jour impossible';
|
|
$output = new SetInfosEntrepReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Insertion actionnaire
|
|
if ( trim($tabActio['siren'])!='' ) {
|
|
$nom = $pays = $dateMAJ = '';
|
|
$ppPm = 'P';
|
|
$pct = trim(str_replace(',','.',$tabActio['pct']))*1;
|
|
$siren2 = preg_replace('/[^0-9]/','', $tabActio['siren']);
|
|
$entrep2 = $iInsee->getIdentiteEntreprise($siren);
|
|
$nom2 = $entrep2['Nom'];
|
|
$pays2 = $entrep2['Pays'];
|
|
if ($pays2=='') $pays2='FRA';
|
|
|
|
if (substr($entrep2['FJ'],0,1)*1<>1) $ppPm='M';
|
|
$entrep = $iInsee->getIdentiteEntreprise($siren2);
|
|
$nom = $entrep['Nom'];
|
|
$pays = trim($entrep['Pays']);
|
|
if ($pays=='') $pays='FRA';
|
|
if (trim($tabActio['nom'])!='') $nom = $tabActio['nom'];
|
|
if ($tabActio['pays']!='XXX') $pays = $tabActio['pays'];
|
|
|
|
if (trim($tabActio['dateMAJ'])!='JJ/MM/AAAA' && trim($tabActio['dateMAJ'])!=''){
|
|
$dateMAJ = Metier_Util_Date::dateT('d/m/Y', 'Y-m-d', trim($tabActio['dateMAJ']));
|
|
}
|
|
|
|
if ($tabActio['majMin']=='maj') $majMin='+';
|
|
elseif ($tabActio['majMin']=='min') $majMin='-';
|
|
else $majMin='';
|
|
|
|
$tabUpdate = array(
|
|
//'Siren1'=> $siren,
|
|
'Pmin'=> $pct,
|
|
'Pmax'=> $pct,
|
|
'MajMin'=> $majMin,
|
|
'PpPm'=> $ppPm,
|
|
//'Siren2'=> $siren2,
|
|
//'RaisonSociale'=> $nom,
|
|
//'Pays'=> $pays,
|
|
'dateLien'=> $dateMAJ,
|
|
);
|
|
|
|
$tabInsert1 = array_merge($tabUpdate, array('ActionPart' => 1), array(
|
|
'Siren1'=> $siren,
|
|
'Siren2'=> $siren2,
|
|
'RaisonSociale'=> $nom,
|
|
'Pays'=> $pays,
|
|
'actif'=> 1,
|
|
'source'=> 1900,
|
|
'dateInsert'=> date('YmdHis'))
|
|
);
|
|
$res = $iDb->select('jo.liens', 'count(*)',
|
|
"Siren1=$siren AND (Siren2=$siren2 OR (RaisonSociale='$nom' AND Pays='$pays'))");
|
|
if ($res[0][0]>0) {
|
|
if (!$iDb->update('jo.liens', array_merge($tabUpdate,array('ActionPart'=>1)), "siren=$siren AND (Siren2=$siren2 OR (RaisonSociale='$nom' AND Pays='$pays'))", true))
|
|
$errMaj=1016166;
|
|
} else {
|
|
if (!$iDb->insert('jo.liens', $tabInsert1, true))
|
|
$errMaj=1016167;
|
|
}
|
|
|
|
$tabInsert2 = array_merge($tabUpdate, array('ActionPart' => 2), array(
|
|
'Siren1' => $siren2,
|
|
'Siren2'=> $siren,
|
|
'RaisonSociale'=> $nom2,
|
|
'Pays'=> $pays2,
|
|
'actif'=> 1,
|
|
'source'=> 1900,
|
|
'dateInsert'=> date('YmdHis'))
|
|
);
|
|
$res=$iDb->select('jo.liens', 'count(*)', "Siren1=$siren2 AND (Siren2=$siren OR (RaisonSociale='$nom2' AND Pays='$pays2'))");
|
|
if ($res[0][0]>0) {
|
|
if (!$iDb->update('jo.liens', array_merge($tabUpdate,array('ActionPart'=>2)), "siren=$siren2 AND (Siren2=$siren OR (RaisonSociale='$nom2' AND Pays='$pays2'))", true))
|
|
$errMaj=1016168;
|
|
} else {
|
|
if (!$iDb->insert('jo.liens', $tabInsert2, true))
|
|
$errMaj=1016169;
|
|
}
|
|
}
|
|
// Fin insertion actionnaire
|
|
|
|
//Insertion participation
|
|
if ( trim($tabParti['siren'])<>'' ) {
|
|
$nom = $pays = $dateMAJ = '';
|
|
$ppPm = 'P';
|
|
$pct = trim(str_replace(',','.',$tabParti['pct']))*1;
|
|
$siren2 = preg_replace('/[^0-9]/','', $tabParti['siren']);
|
|
$entrep2 = $iInsee->getIdentiteEntreprise($siren);
|
|
$nom2 = $entrep2['Nom'];
|
|
$pays2 = $entrep2['Pays'];
|
|
if ($pays2=='') $pays2='FRA';
|
|
|
|
if (substr($entrep2['FJ'],0,1)*1<>1) $ppPm='M';
|
|
$entrep = $iInsee->getIdentiteEntreprise($siren2);
|
|
$nom = $entrep['Nom'];
|
|
$pays = trim($entrep['Pays']);
|
|
if ( $pays=='' ) $pays='FRA';
|
|
if ( trim($tabParti['nom'])<>'' ) $nom=$tabParti['nom'];
|
|
if ( $tabParti['pays']<>'XXX' ) $pays=$tabParti['pays'];
|
|
|
|
if (trim($tabParti['dateMAJ'])<>'JJ/MM/AAAA' && trim($tabParti['dateMAJ'])<>'')
|
|
$dateMAJ=Metier_Util_Date::dateT('d/m/Y', 'Y-m-d', trim($tabParti['dateMAJ']));
|
|
|
|
if ($tabParti['majMin']=='maj') $majMin='+';
|
|
elseif ($tabParti['majMin']=='min') $majMin='-';
|
|
else $majMin='';
|
|
|
|
$tabUpdate = array(
|
|
'Pmin'=> $pct,
|
|
'Pmax'=> $pct,
|
|
'MajMin'=> $majMin,
|
|
'PpPm'=> $ppPm,
|
|
'dateLien'=> $dateMAJ,
|
|
);
|
|
|
|
$tabInsert1 = array_merge($tabUpdate, array( 'ActionPart' => 2 ), array(
|
|
'Siren1'=> $siren,
|
|
'Siren2'=> $siren2,
|
|
'RaisonSociale'=> $nom,
|
|
'Pays'=> $pays,
|
|
'actif'=> 1,
|
|
'source'=> 1900,
|
|
'dateInsert'=> date('YmdHis'))
|
|
);
|
|
$res=$iDb->select('jo.liens', 'count(*)', "Siren1=$siren AND (Siren2=$siren2 OR (RaisonSociale='$nom' AND Pays='$pays'))");
|
|
if ($res[0][0]>0) {
|
|
if (!$iDb->update('jo.liens', array_merge($tabUpdate,array('ActionPart'=>2)), "siren=$siren AND (Siren2=$siren2 OR (RaisonSociale='$nom' AND Pays='$pays'))", true))
|
|
$errMaj=10168;
|
|
} else {
|
|
if (!$iDb->insert('jo.liens', $tabInsert1, true))
|
|
$errMaj=10169;
|
|
}
|
|
|
|
$tabInsert2 = array_merge($tabUpdate, array( 'ActionPart' => 1 ), array(
|
|
'Siren1'=> $siren2,
|
|
'Siren2'=> $siren,
|
|
'RaisonSociale'=> $nom2,
|
|
'Pays'=> $pays2,
|
|
'actif'=> 1,
|
|
'source'=> 1900,
|
|
'dateInsert'=> date('YmdHis'))
|
|
);
|
|
$res=$iDb->select('jo.liens', 'count(*)', "Siren1=$siren2 AND (Siren2=$siren OR (RaisonSociale='$nom2' AND Pays='$pays2'))");
|
|
if ($res[0][0]>0) {
|
|
if (!$iDb->update('jo.liens', array_merge($tabUpdate,array('ActionPart'=>1)), "siren=$siren2 AND (Siren2=$siren OR (RaisonSociale='$nom2' AND Pays='$pays2'))", true))
|
|
$errMaj=10170;
|
|
} else {
|
|
if (!$iDb->insert('jo.liens', $tabInsert2, true))
|
|
$errMaj=10171;
|
|
}
|
|
}
|
|
// Fin insertion participation
|
|
|
|
if ($errMaj>0){
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Mise a jour impossible';
|
|
} else {
|
|
$result = true;
|
|
}
|
|
}
|
|
$output = new SetInfosEntrepReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Informations Mandataires
|
|
* @param SetInfosMandataire $infos Informations sur le mandataire à créer ou à ajouter (ajout si id absent)
|
|
* @return boolean
|
|
*/
|
|
public function setMandataire($infos)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$result = false;
|
|
|
|
$type = substr(strtoupper($infos->type),0,1);
|
|
$stag = substr(strtoupper($infos->type),1,1);
|
|
if ( $stag=='S' ) {
|
|
$stag = 1;
|
|
} else {
|
|
$stag = 0;
|
|
}
|
|
if ( in_array($type, array('A', 'H', 'M', 'V', 'N', 'T')) ) {
|
|
$tabUpdate = array(
|
|
'sirenGrp' => substr($infos->sirenGrp,0,9)*1,
|
|
'nicGrp' => substr($infos->sirenGrp,9,5)*1,
|
|
'sirenMand' => substr($infos->sirenMand,0,9)*1,
|
|
'nicMand' => substr($infos->sirenMand,9,5)*1,
|
|
'Nom' => ucwords(strtolower($infos->Nom)),
|
|
'Prenom' => ucwords(strtolower($infos->Prenom)),
|
|
'type' => $type,
|
|
'stagiaire' => $stag,
|
|
'coursAppel' => intval($infos->coursAppel),
|
|
'coursAppel2' => intval($infos->coursAppel2),
|
|
'tribunal' => $infos->tribunal,
|
|
'Statut' => strtoupper($infos->Statut),
|
|
'adresse' => ucwords($infos->adresse),
|
|
'adresseComp' => strtoupper($infos->adresseComp),
|
|
'cp' => intval($infos->cp),
|
|
'ville' => strtoupper($infos->ville),
|
|
'tel' => $infos->tel,
|
|
'fax' => $infos->fax,
|
|
'email' => $infos->email,
|
|
'web' => $infos->web,
|
|
'contact' => $infos->contact,
|
|
'idUser' => $this->User->id,
|
|
);
|
|
|
|
$model = new Application_Model_JoTabMandataires();
|
|
$id = intval(str_replace('m','', ''.$infos->id));
|
|
if ( intval($id)!=0 ) {
|
|
try {
|
|
$model->update($tabUpdate, 'id='.$id);
|
|
return true;
|
|
} catch (Zend_Db_Exception $e){
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
} else {
|
|
try {
|
|
$tabUpdate['dateInsert'] = date('YmdHis');
|
|
$model->insert($tabUpdate);
|
|
return true;
|
|
} catch (Zend_Db_Exception $e){
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Supprime une annonce issue de la collecte
|
|
* @param string $idAnn
|
|
* @param string $siret
|
|
* @return SupprAnnonceCollecteReturn
|
|
*/
|
|
public function supprAnnonceCollecte($idAnn, $siret=null)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
if (empty($siret)) $siret = 0;
|
|
$error = new ErrorType();
|
|
$result = false;
|
|
|
|
if (!$this->checkEdition())
|
|
{
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code Client Incorrect';
|
|
}
|
|
else
|
|
{
|
|
$siren = substr($siret,0,9)*1;
|
|
$iDb = new Metier_Util_Db();
|
|
$idAnn = preg_replace('/^0\./','', ''.$idAnn)*1;
|
|
|
|
if ($idAnn>0)
|
|
{
|
|
if ($iDb->update('jo.annonces',array(
|
|
'dateSuppr'=>date('YmdHis'),
|
|
'idSuppr'=>$this->User->id),
|
|
"id=$idAnn", false))
|
|
{
|
|
Metier_Util_Log::write('I',"Suppression de l'annonce collectée n°$idAnn ($siret)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$result = true;
|
|
}
|
|
else
|
|
{
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Suppression de l\'annonce impossible';
|
|
Metier_Util_Log::write('I',"Suppression impossible de l'annonce collectée n°$idAnn ($siret)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'idAnn incorrect';
|
|
}
|
|
}
|
|
$output = new SupprAnnonceCollecteReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Récupère le mandataire par son id
|
|
* @param int $id Identifiant du mandataire
|
|
* @return string
|
|
*/
|
|
public function getMandataire($id)
|
|
{
|
|
$this->authenticate();
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabRet = $iInsee->getMandataire($id);
|
|
return json_encode($tabRet);
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
/**
|
|
* Duplique une annonce issue de la collecte
|
|
* @param string $idAnn
|
|
* @param string $siret
|
|
* @return DupliqueAnnonceReturn
|
|
*/
|
|
public function dupliqueAnnonceCollecte($idAnn, $siret = null)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
if (empty($siret)) $siret = '';
|
|
$error = new ErrorType();
|
|
$result = 0;
|
|
|
|
if (!$this->checkEdition()) {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code Client Incorrect';
|
|
} else {
|
|
$siren = intval(substr($siret,0,9));
|
|
$nic = intval(substr($siret,9,5));
|
|
$iDb = new Metier_Util_Db();
|
|
$idAnn = intval(preg_replace('/^0\./','', ''.$idAnn));
|
|
if ($idAnn>0 && $siren>1000){
|
|
$res = $iDb->select('jo.annonces', '*', "id=$idAnn", false, MYSQL_ASSOC);
|
|
if (count($res)==0) {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Annonce inexistante';
|
|
} else {
|
|
$annonce = $res[0];
|
|
// Suppression des zones inexistantes dans la table ou devant être vides
|
|
unset($annonce['id']);
|
|
unset($annonce['nic']);//=$nic;
|
|
$annonce['siren'] = $siren;
|
|
$annonce['nic'] = $nic;
|
|
if ($iDb->insert('jo.annonces', $annonce, false)) {
|
|
Metier_Util_Log::write('I',"Duplication de l'annonce collectée n°$idAnn sur $siret",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$result = 1;
|
|
} else {
|
|
Metier_Util_Log::write('I',"Suppression impossible de l'annonce collectée n°$idAnn ($siret)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Suppression de l\'annonce impossible';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$output = new DupliqueAnnonceCollecte();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* 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, LPAD(siren,9,0) AS 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;
|
|
}
|
|
|
|
/**
|
|
* Enregistrement de document actes ou status d'association
|
|
* @param string $siren Numéro Siren
|
|
* @param string $waldec Numéro waldec
|
|
* @param string $type Type d'acte (ST)
|
|
* @param string $libelle Libellé de l'acte
|
|
* @param string $date Date de l'acte au format AAAAMMDD
|
|
* return boolean
|
|
*/
|
|
public function setActeAsso( $siren, $waldec, $type, $libelle, $date )
|
|
{
|
|
$this->authenticate();
|
|
if (!$this->checkEdition()) {
|
|
$this->sendError('0902');
|
|
}
|
|
|
|
($type == 'ST') ? $type_acte = 'ST' : $type_acte = 'ST';
|
|
|
|
$data = array(
|
|
'siren' => $siren,
|
|
'waldec' => $waldec,
|
|
'pdfLink' => '',
|
|
'pdfSize' => '',
|
|
'pdfVer' => '',
|
|
'pdfPage' => '',
|
|
'date_acte' => Metier_Util_Date::dateT('Ymd', 'Y-m-d', $date),
|
|
'type_acte' => $type_acte,
|
|
'type_acte_libelle' => $libelle,
|
|
);
|
|
|
|
//Save
|
|
try {
|
|
$doc = new Application_Model_AssoActes();
|
|
$id = $doc->insert($data);
|
|
} catch (Zend_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
|
|
/**
|
|
* Suppression logique d'une annonce relative à une entité
|
|
* @param integer $source 0=Collecte, 1=BODACC, 2=B.A.L.O, 3=JO Association, 4=Boamp
|
|
* @param string $idAnn Identifiant de l'annonce
|
|
* @param string $siret Siren de l'entreprise ou Siret de l'établissement
|
|
* @return SupprAnnonceReturn
|
|
*/
|
|
public function supprAnnonce($source=0, $idAnn, $siret=0)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
if (empty($siret)) $siret = 0;
|
|
if (empty($source)) $source = 0;
|
|
$error = new ErrorType();
|
|
$result = false;
|
|
|
|
if (!$this->checkEdition())
|
|
{
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code Client Incorrect';
|
|
}
|
|
else
|
|
{
|
|
|
|
$siren = substr($siret,0,9);
|
|
$iDb = new Metier_Util_Db();
|
|
switch ($source)
|
|
{
|
|
case 0:
|
|
$idAnn = preg_replace('/^0\./','', ''.$idAnn)*1;
|
|
$table = 'jo.annonces';
|
|
break;
|
|
case 1:
|
|
if (intval($idAnn)<0){
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code annonce Incorrect';
|
|
} else {
|
|
$strSql = "AND siren=$siren";
|
|
$table = 'jo.bodacc_detail';
|
|
}
|
|
break;
|
|
case 3:
|
|
$table = 'asso';
|
|
break;
|
|
case 2:
|
|
case 4:
|
|
default:
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Cas non géré';
|
|
break;
|
|
}
|
|
if (intval($idAnn)>0 && $iDb->update($table, array(
|
|
'dateSuppr' => date('YmdHis'),
|
|
'idSuppr' => $this->User->id),
|
|
"id=$idAnn $strSql", false))
|
|
{
|
|
Metier_Util_Log::write('I',"Suppression de l'annonce en source $source n°$idAnn ($siret)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 0;
|
|
$error->errmsg = '';
|
|
$result = true;
|
|
} else {
|
|
Metier_Util_Log::write('I',"Suppression impossible de l'annonce en source $source n°$idAnn ($siret)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Suppression de l\'annonce impossible';
|
|
}
|
|
}
|
|
$output = new SupprAnnonceReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Duplication d'une annonce relative à une entité
|
|
*
|
|
* @param integer $source 0=Collecte, 1=BODACC, 2=B.A.L.O, 3=JO Association, 4=Boamp
|
|
* @param string $idAnn Identifiant de l'annonce
|
|
* @param string $siretIn Siren de l'entreprise ou Siret de l'établissement de l'annonce à duppliquer
|
|
* @param string $siretOut Siren/Siret de l'entreprise ou étab sur lequel il faut dupliquer l'annonce
|
|
* @return DupliqueAnnonceReturn
|
|
*/
|
|
public function dupliqueAnnonce($source=0, $idAnn, $siretIn=0, $siretOut=0)
|
|
{
|
|
Metier_Util_Log::write('I',"Demande de duplication d'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
$this->authenticate();
|
|
//Initialisation
|
|
if (empty($siret)) $siret = 0;
|
|
if (empty($source)) $source = 0;
|
|
$error = new ErrorType();
|
|
$result = false;
|
|
|
|
if (!$this->checkEdition())
|
|
{
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code Client Incorrect';
|
|
}
|
|
else
|
|
{
|
|
$sirenIn = substr($siretIn,0,9)*1;
|
|
$nicIn = substr($siretIn,9,5)*1;
|
|
$sirenOut = substr($siretOut,0,9)*1;
|
|
$nicOut = substr($siretOut,9,5)*1;
|
|
$iDb = new Metier_Util_Db();
|
|
$strSql='';
|
|
switch ($source)
|
|
{
|
|
//
|
|
case 0:
|
|
$idAnn = preg_replace('/^0\./','', ''.$idAnn)*1;
|
|
$table = 'jo.annonces';
|
|
break;
|
|
|
|
//Bodacc
|
|
case 1:
|
|
if (intval($idAnn)<0) {
|
|
//@todo : Must be possible
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Code annonce Incorrect';
|
|
} else {
|
|
if (intval($sirenIn)>0) $strSql.="AND siren=$sirenIn";
|
|
$table = 'jo.bodacc_detail';
|
|
}
|
|
break;
|
|
|
|
//Association
|
|
case 3:
|
|
$table = 'jo.asso';
|
|
break;
|
|
//
|
|
case 2:
|
|
//
|
|
case 4:
|
|
//
|
|
default:
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Cas non géré';
|
|
break;
|
|
}
|
|
|
|
if (intval($idAnn)>0) {
|
|
//@todo : define fields LPAD(siren,9,0) as siren
|
|
$res = $iDb->select($table, '*', "id=$idAnn $strSql", false, MYSQL_ASSOC);
|
|
|
|
if (count($res)==0) {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Annonce inexistante';
|
|
} else {
|
|
|
|
/* Si table = asso => UPDATE de la ligne */
|
|
if ($table == 'jo.asso'){
|
|
//$annonce = $res[0];
|
|
$annonce['siren'] = $sirenOut;
|
|
$annonce['sirenValide'] = 2;
|
|
$annonce['dateUpdate'] = date('YmdHis');
|
|
$annonce['idSirenage'] = $this->User->id;
|
|
$annonce['nic'] = $nicOut;
|
|
if ($nicOut>0) $annonce['nicValide'] = 2;
|
|
if ($iDb->update($table, $annonce, "id=".$idAnn, true, true)) {
|
|
Metier_Util_Log::write('I',"Duplication de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
|
|
//Si WALDEC présent dans l'annonce alors on rapproche tout
|
|
if ($res['Waldec']!='') {
|
|
$iDb->update($table, $annonce, "Waldec=".$res['Waldec'], false);
|
|
}
|
|
$result = true;
|
|
} else {
|
|
Metier_Util_Log::write('I',"Duplication impossible de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut) : ".mysql_error(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 1;
|
|
$error->errmsg = "Duplication de l'annonce impossible";
|
|
}
|
|
}
|
|
/* Si sirenIn = 0 et table = bodacc_detail => INSERT + UPDATE */
|
|
elseif (intval($sirenIn) == 0 && $table == 'jo.bodacc_detail' ) {
|
|
$annonce = $res[0];
|
|
$annonce['siren'] = $sirenOut;
|
|
$annonce['sirenValide'] = 2;
|
|
$annonce['dateInsert'] = date('YmdHis');
|
|
$annonce['idSirenage'] = $this->User->id;
|
|
$annonce['nic'] = $nicOut;
|
|
if ($nicOut>0) $annonce['nicValide'] = 2;
|
|
if ($iDb->insert($table, $annonce, true, true)) {
|
|
Metier_Util_Log::write('I',"Duplication de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$result = true;
|
|
$data = array(
|
|
'idSuppr' => $this->User->id,
|
|
'dateSuppr' => date('YmdHis'),
|
|
);
|
|
$iDb->update($table, $data, "id=$idAnn $strSql", true, true);
|
|
} else {
|
|
Metier_Util_Log::write('I',"Duplication impossible de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut) : ".mysql_error(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 1;
|
|
$error->errmsg = "Duplication de l'annonce impossible";
|
|
}
|
|
}
|
|
/* si sirenIn != 0 et table = bodacc_detail => insert */
|
|
elseif (intval($sirenIn) != 0 && $table == 'jo.bodacc_detail') {
|
|
$annonce = $res[0];
|
|
$annonce['siren'] = $sirenOut;
|
|
$annonce['sirenValide'] = 2;
|
|
$annonce['dateInsert'] = date('YmdHis');
|
|
$annonce['idSirenage'] = $this->User->id;
|
|
$annonce['nic'] = $nicOut;
|
|
if ($nicOut>0) $annonce['nicValide'] = 2;
|
|
if ($iDb->insert($table, $annonce, true, true)) {
|
|
Metier_Util_Log::write('I',"Duplication de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$result = true;
|
|
} else {
|
|
Metier_Util_Log::write('I',"Duplication impossible de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut) : ".mysql_error(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 1;
|
|
$error->errmsg = "Duplication de l'annonce impossible";
|
|
}
|
|
|
|
}
|
|
/* Si table = annonces => INSERT */
|
|
elseif ($table == 'jo.annonces'){
|
|
$annonce = $res[0];
|
|
// Suppression des zones inexistantes dans la table ou devant être vides
|
|
unset($annonce['id']);
|
|
unset($annonce['nic']);
|
|
$annonce['idSaisie'] = $this->User->id;
|
|
if ($iDb->insert($table, $annonce, true, true)) {
|
|
Metier_Util_Log::write('I',"Duplication de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$result = true;
|
|
} else {
|
|
Metier_Util_Log::write('I',"Duplication impossible de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut) : ".mysql_error(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 1;
|
|
$error->errmsg = "Duplication de l'annonce impossible";
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
Metier_Util_Log::write('I',"Duplication impossible de l'annonce en source $source sur n°$idAnn (siretIn=$siretIn, siretOut=$siretOut)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
$error->errnum = 1;
|
|
$error->errmsg = "Duplication de l'annonce impossible";
|
|
}
|
|
}
|
|
$output = new DupliqueAnnonceReturn();
|
|
$output->error = $error;
|
|
$output->result = $result;
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Modification du code evenement d'une annonce
|
|
* @param string $siren
|
|
* @param string $id
|
|
* @param string[] $codeEven
|
|
* @return boolean
|
|
*/
|
|
public function setAnnonceEven($siren, $id, $codeEven)
|
|
{
|
|
$this->authenticate();
|
|
$iDb = new Metier_Util_Db();
|
|
|
|
$list = array();
|
|
if (is_object($codeEven)){
|
|
$list = $codeEven->item;
|
|
} else {
|
|
$list = $codeEven;
|
|
}
|
|
|
|
//Get Rubrique of event
|
|
$eventM = new Application_Model_JoTabEvenements();
|
|
$sql = $eventM->select()->where('codEven=?', $list[0]);
|
|
$row = $eventM->fetchRow($sql);
|
|
|
|
if (count($list)>0){
|
|
$tabUpdate = array(
|
|
'typeEven' => implode(';',$list),
|
|
'Rubrique' => $row->Rubrique,
|
|
'idSirenage' => $this->User->id,
|
|
);
|
|
if ($iDb->update('jo.bodacc_detail', $tabUpdate, "siren='$siren' AND id='$id'")){
|
|
Metier_Util_Log::write('I',"setAnnonceEven (siren=$siren, list=$list)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Enregistre une information de contact
|
|
* @param string $siret
|
|
* SIRET ou SIREN
|
|
* @param string $type
|
|
* Type de l'information (tel|fax|mail|mob|web)
|
|
* @param string $value
|
|
* Valeur
|
|
* @param string $info
|
|
* Information complémentaire (use for type "tel" as description)
|
|
* @param int id
|
|
* Id (only for editing)
|
|
* @param boolean $delete
|
|
* Marqueur de suppression
|
|
* @return int
|
|
* Retourne l'identifiant de l'élément ou le nombre de ligne lors d'un update
|
|
*/
|
|
public function setContactEt($siret, $type, $value, $info, $id=null, $delete=false)
|
|
{
|
|
$this->authenticate();
|
|
$idUtilisateur = $this->User->id;
|
|
|
|
//Delete
|
|
if ($delete === true) {
|
|
|
|
try {
|
|
$telephonieM = new Application_Model_JoTelephonie();
|
|
$data = array(
|
|
'dateSuppr'=> date('YmdHis'),
|
|
'idSuppr' => $idUtilisateur,
|
|
);
|
|
$id = $telephonieM->update($data, 'id='.$id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
//Control input value
|
|
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,10,5);
|
|
if (intval($nic)==0) {
|
|
$nic = '00000';
|
|
}
|
|
|
|
if ( !in_array($type, array('an8','domaines','fax','logo','mail','mob','tel','web') ) ) {
|
|
throw new SoapFault('ERR', "unknow value for type");
|
|
}
|
|
|
|
switch($type) {
|
|
case 'mail':
|
|
case 'web':
|
|
case 'domaines':
|
|
$info = $value;
|
|
$value = 0;
|
|
break;
|
|
case 'tel' :
|
|
$value = intval(strtr($value, array(' ' => '', '.' => '', '-' => '')));
|
|
break;
|
|
}
|
|
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$entrep = $iInsee->getIdentiteLight($siren, $nic);
|
|
if ( empty($entrep['id']) || intval($entrep['id'])==0 ) {
|
|
$this->sendError('1020');
|
|
}
|
|
|
|
$data = array(
|
|
'siren' => $siren,
|
|
'nic' => $nic,
|
|
'dateProvPartenaire'=> date('Y').date('m').date('d'),
|
|
'typeTel' => $type,
|
|
'infoTel' => $info,
|
|
'telephone' => $value,
|
|
'actif' => 1,
|
|
'partenaire' => 175,
|
|
);
|
|
|
|
if ( $id === null ) {
|
|
|
|
try {
|
|
$data['idUtilisateur'] = $idUtilisateur;
|
|
$data['dateInsert'] = date('YmdHis');
|
|
$telephonieM = new Application_Model_JoTelephonie();
|
|
$id = $telephonieM->insert($data);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
} else {
|
|
|
|
$data['idUpdate'] = $idUtilisateur;
|
|
$data['dateUpdate'] = date('YmdHis');
|
|
|
|
try {
|
|
$telephonieM = new Application_Model_JoTelephonie();
|
|
$id = $telephonieM->update($data, 'id='.$id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* Get a contact
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return string
|
|
*/
|
|
public function getContactEt($id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$contactM = new Application_Model_JoTelephonie();
|
|
|
|
try {
|
|
$sql = $contactM->select(true)->columns(array(
|
|
'id',
|
|
'LPAD(siren,9,0) AS siren',
|
|
'LPAD(nic,5,0) AS nic',
|
|
'dateProvPartenaire',
|
|
'typeTel',
|
|
'infoTel',
|
|
'telephone',
|
|
'actif',
|
|
'partenaire',
|
|
'idUtilisateur',
|
|
'DATE_FORMAT(dateInsert, "%Y-%m-%d") AS dateInsert',
|
|
'idUpdate',
|
|
'DATE_FORMAT(dateUpdate, "%Y-%m-%d") AS dateUpdate',
|
|
'idSuppr',
|
|
'DATE_FORMAT(dateSuppr, "%Y-%m-%d") AS dateSuppr',
|
|
))->where('id=?',$id);
|
|
$row = $contactM->fetchRow($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
$result = $row->toArray();
|
|
|
|
$userM = new Application_Model_Sdv1Utilisateurs();
|
|
|
|
if ( $result['idUtilisateur']!=0 ) {
|
|
$sql = $userM->select(true)->columns(array('login', 'nom', 'prenom'))->where('id=?', $result['idUtilisateur']);
|
|
$row = $userM->fetchRow($sql);
|
|
$result['idUtilisateurName'] = $row->nom . ' ' . $row->prenom;
|
|
}
|
|
|
|
if ( $result['idUpdate']!=0 ) {
|
|
$sql = $userM->select(true)->columns(array('login', 'nom', 'prenom'))->where('id=?', $result['idUpdate']);
|
|
$row = $userM->fetchRow($sql);
|
|
$result['idUpdateName'] = $row->nom . ' ' . $row->prenom;
|
|
}
|
|
|
|
if ( $result['idSuppr']!=0 ) {
|
|
$sql = $userM->select(true)->columns(array('login', 'nom', 'prenom'))->where('id=?', $result['idSuppr']);
|
|
$row = $userM->fetchRow($sql);
|
|
$result['idSupprName'] = $row->nom . ' ' . $row->prenom;
|
|
}
|
|
|
|
return json_encode($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* Saisie d'un bilan
|
|
* @param string $siren
|
|
* SIREN de l'entité
|
|
* @param string $cloture
|
|
* Date de cloture original
|
|
* @param string $type
|
|
* Type original du bilan
|
|
* @param BilanInfos $data
|
|
* Postes et Information du bilan
|
|
* @param string $step (normal|nocheck|onlycheck)
|
|
* Etape
|
|
* @return int
|
|
* @throws SoapFault
|
|
*/
|
|
public function setBilan($siren, $cloture, $type, $data, $step = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
// --- Control input value
|
|
if ( strlen($siren)!=9 ) {
|
|
$this->sendError('1010');
|
|
}
|
|
|
|
$tabPostes = array();
|
|
|
|
// --- Control des valeurs
|
|
if ( !in_array($data->unite, array('', 'U', 'K', 'M')) ) {
|
|
throw new SoapFault('MSG', "Erreur Unite");
|
|
}
|
|
if (!preg_match('/[0-9]{8}/', $data->dateCloture)) {
|
|
throw new SoapFault('MSG', "Erreur Date de cloture");
|
|
}
|
|
if ($data->dateCloturePre != 'AAAAMMJJ' && !preg_match('/[0-9]{8}/', $data->dateCloturePre)) {
|
|
throw new SoapFault('MSG', "Erreur Date de cloture précédente");
|
|
}
|
|
if ($data->dateCloturePre == 'AAAAMMJJ') {
|
|
$data->dateCloturePre = 0;
|
|
}
|
|
if (intval($data->dureeMois) < 1) {
|
|
throw new SoapFault('MSG', "Erreur Durée");
|
|
}
|
|
if ($data->dureeMoisPre != 0 && intval($data->dureeMoisPre)<1) {
|
|
throw new SoapFault('MSG', "Erreur Durée précédente");
|
|
}
|
|
if (!empty($data->postes)) {
|
|
$listPostes = explode(';', $data->postes);
|
|
foreach($listPostes as $strPoste) {
|
|
$itemPoste = explode('=', $strPoste);
|
|
if ( !is_numeric($itemPoste[1]) ) {
|
|
throw new SoapFault('MSG', "Erreur poste ".$itemPoste[0]);
|
|
break;
|
|
}
|
|
$tabPostes[$itemPoste[0]] = intval($itemPoste[1]);
|
|
}
|
|
} else {
|
|
throw new SoapFault('MSG', "Aucun poste saisi");
|
|
}
|
|
|
|
// --- Mathematic control
|
|
if ($step != 'nocheck' && count($tabPostes) > 0)
|
|
{
|
|
$control = new Metier_Partenaires_MBilansInput();
|
|
try {
|
|
$control->control($data->typeBilan, $tabPostes);
|
|
} catch (Exception $e) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
// --- End of Mathematic control
|
|
|
|
if ( $step == 'onlycheck' ) {
|
|
return 1;
|
|
}
|
|
// --- Insertion dans la bdd
|
|
else {
|
|
|
|
try {
|
|
$bilansM = new Application_Model_JoBilans();
|
|
$sql = $bilansM->select()
|
|
->where('siren=?', $siren)
|
|
->where('dateExercice=?', $cloture)
|
|
->where('typeBilan=?', $type);
|
|
$row = $bilansM->fetchRow($sql);
|
|
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
$postesDiff = array();
|
|
|
|
// Nouveau bilan
|
|
if ($row === null) {
|
|
// --- Define data
|
|
$dataToInsert = array(
|
|
'siren' => $siren,
|
|
'dateProvPartenaire' => date('Ymd'),
|
|
'dateExercice' => $data->dateCloture,
|
|
'dateExercicePre' => $data->dateCloturePre,
|
|
'dureeExercice' => $data->dureeMois,
|
|
'dureeExercicePre' => $data->dureeMoisPre,
|
|
'monnaie' => 'EUR',
|
|
'typeBilan' => $data->typeBilan,
|
|
'monnaieOrigine' => 'EUR',
|
|
'unite' => $data->unite,
|
|
'postes' => $data->postes,
|
|
'partenaire' => 1,
|
|
'confidentiel' => 0,
|
|
'dateInsert' => date('YmdHis'),
|
|
);
|
|
|
|
// --- Insert
|
|
try {
|
|
$id = $bilansM->insert($dataToInsert);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
// Mise à jour
|
|
else {
|
|
// --- Make the diff
|
|
$postesDiff = array_diff(explode(';', $data->postes), explode(';',$row->postes));
|
|
|
|
// --- Backup in historiques
|
|
$historiquesM = new Application_Model_HistoriquesBilans();
|
|
$backupData = $row->toArray();
|
|
unset($backupData['id']);
|
|
try {
|
|
$historiquesM->insert($backupData);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// --- Define data
|
|
$dataToUpdate = array(
|
|
'dateProvPartenaire' => date('Ymd'),
|
|
'dateExercice' => $data->dateCloture,
|
|
'dateExercicePre' => $data->dateCloturePre,
|
|
'dureeExercice' => $data->dureeMois,
|
|
'dureeExercicePre' => $data->dureeMoisPre,
|
|
'monnaie' => 'EUR',
|
|
'typeBilan' => $data->typeBilan,
|
|
'monnaieOrigine' => 'EUR',
|
|
'unite' => $data->unite,
|
|
'postes' => $data->postes,
|
|
'partenaire' => 1,
|
|
'confidentiel' => 0,
|
|
'dateInsert' => date('YmdHis'),
|
|
);
|
|
|
|
// --- Update
|
|
try {
|
|
$id = $bilansM->update($dataToUpdate, 'id = '.$row->id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($id)) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
|
|
// --- Save user
|
|
$userM = new Application_Model_JoBilansUser();
|
|
try {
|
|
$userM->insert(array(
|
|
'idUtilisateur' => $this->User->id,
|
|
'login' => $this->User->login,
|
|
'siren' => $siren,
|
|
'dateExercice' => $data->dateCloture,
|
|
'typeBilan' => $data->typeBilan,
|
|
'dateAction' => date('YmdHis'),
|
|
'postesDiff' => implode(';', $postesDiff),
|
|
));
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Créer un identifiant local pour un pays
|
|
* @param string $infos
|
|
* @param string $id
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function setCountryId($infos, $id = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$data = json_decode($infos, true);
|
|
|
|
if ($id!==null) {
|
|
|
|
//Update
|
|
try {
|
|
$countryIdM = new Application_Model_JoTabIdLocal();
|
|
$id = $countryIdM->update($data, 'id = '.$id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
} else {
|
|
|
|
//Insert
|
|
try {
|
|
$countryIdM = new Application_Model_JoTabIdLocal();
|
|
$id = $countryIdM->insert($data);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* Get lien informations
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return string
|
|
*/
|
|
public function getLien($id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$lienM = new Application_Model_JoLiens();
|
|
try {
|
|
$row = $lienM->find($id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
$result = $row->current()->toArray();
|
|
return json_encode($result);
|
|
}
|
|
|
|
/**
|
|
* Définition d'un lien
|
|
* @param string $infos
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function setLien($infos, $id=null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$dataLien = json_decode($infos, true);
|
|
$dataLien['source'] = 1900;
|
|
|
|
$lienM = new Application_Model_JoLiens();
|
|
|
|
//Test si PDetention >= 100
|
|
if ($dataLien['actif']!=0) {
|
|
$sql = $lienM->select()->from($lienM, array(
|
|
'idPar', new Zend_Db_Expr('SUM( PDetention ) AS sumDet')
|
|
))
|
|
->where('idPar=?',$dataLien['idPar']);
|
|
if (null !== $id) {
|
|
$sql->where('id!=?', $id);
|
|
}
|
|
$sql->where('actif=?',1)->where('dateSuppr=?','0000-00-00 00:00:00');
|
|
$result = $lienM->fetchRow($sql);
|
|
if ( null !== $result ) {
|
|
if ( (float) ($result->sumDet + $dataLien['PDetention']) > 100.1 ) {
|
|
throw new SoapFault('ERR', "Erreur Detention sup 100%");
|
|
}
|
|
}
|
|
}
|
|
|
|
//Enregistrer les infos
|
|
if (empty($id)) {
|
|
|
|
$dataLien = array_merge($dataLien, array(
|
|
'idInsert' => $this->User->id,
|
|
'dateInsert' => date('YmdHis'),
|
|
));
|
|
|
|
try {
|
|
$id = $lienM->insert($dataLien);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
//Mise à jour des infos
|
|
else {
|
|
|
|
if ($dataLien['motifUpdate']=="Erreur d'affiliation") {
|
|
$dataLien = array_merge($dataLien, array(
|
|
'idSuppr' => $this->User->id,
|
|
'dateSuppr' => date('YmdHis'),
|
|
));
|
|
} else {
|
|
$dataLien = array_merge($dataLien, array(
|
|
'idUpdate' => $this->User->id,
|
|
'dateUpdate' => date('YmdHis'),
|
|
));
|
|
}
|
|
|
|
try {
|
|
$id = $lienM->update($dataLien, 'id = '.$id);
|
|
} catch (Zend_Db_Statement_Exception $e) {
|
|
if ( $e->getCode() == 1062 ) {
|
|
$id = $lienM->delete('id = '.$id);
|
|
}
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* Définition d'une fiche lien
|
|
* @param string $infos
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function setLienRef($infos, $id=null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$dataRef = json_decode($infos, true);
|
|
$dataRef['source'] = 1900;
|
|
|
|
if (strlen(trim($dataRef['isin']))) {
|
|
$iBourse = new Metier_Partenaires_MBourse();
|
|
if (!$iBourse->isIsin($dataRef['isin'])) {
|
|
throw new SoapFault('ERR', 'Code Isin incorrect.');
|
|
}
|
|
}
|
|
|
|
$refM = new Application_Model_JoLiensRef();
|
|
|
|
//Insert
|
|
if ($id===null) {
|
|
|
|
//Check if exist
|
|
if (intval($dataRef['siren'])!=0) {
|
|
$sql = $refM->select()->from($refM, array('id'))->where('siren=?', $dataRef['siren']);
|
|
$rowset = $refM->fetchRow($sql);
|
|
if ( $rowset!==null ) {
|
|
return $rowset->id;
|
|
}
|
|
}
|
|
|
|
$dataRef = array_merge($dataRef, array(
|
|
'actif' => 1,
|
|
'idInsert' => $this->User->id,
|
|
'dateInsert' => date('YmdHis'))
|
|
);
|
|
|
|
try {
|
|
$id = $refM->insert($dataRef);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
//Update
|
|
else {
|
|
|
|
if (array_key_exists('delete', $dataRef) && $dataRef['delete']==1) {
|
|
|
|
$dataRef = array(
|
|
'idSuppr' => $this->User->id,
|
|
'dateSuppr' => date('YmdHis'),
|
|
);
|
|
|
|
try {
|
|
$id = $refM->update($dataRef, 'id = '.$id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
} else {
|
|
|
|
$dataRef = array_merge($dataRef, array(
|
|
'idUpdate' => $this->User->id,
|
|
'dateUpdate' => date('YmdHis'),
|
|
));
|
|
|
|
try {
|
|
$id = $refM->update($dataRef, 'id = '.$id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* Retourne les informations de référence
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return string
|
|
*/
|
|
public function getLienRef($id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$refM = new Application_Model_JoLiensRef();
|
|
$row = $refM->fetchRow('id='.$id);
|
|
$ouput = '';
|
|
if ($row === null) {
|
|
$output = json_encode(array('Aucun résultat'));
|
|
} else {
|
|
$output = json_encode($row->toArray());
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Liste des documents pour un lien
|
|
* @param int $id
|
|
* @param string $type null|Lien|Entreprise|Siren
|
|
* @throws SoapFault
|
|
* @return LienDoc[]
|
|
*/
|
|
public function getLienDoc($id, $type = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Type = Entreprise => Search id by Siren
|
|
if ($type == 'Siren') {
|
|
$lienrefM = new Application_Model_JoLiensRef();
|
|
$sql = $lienrefM->select()->where('siren=?',$id);
|
|
$row = $lienrefM->fetchRow($sql);
|
|
if (null !== $row) {
|
|
$idNum = $row->id;
|
|
}
|
|
$type = 'Entreprise';
|
|
}
|
|
//Type = Lien
|
|
elseif ($type == 'Lien' || $type == 'Entreprise') {
|
|
$idNum = $id;
|
|
}
|
|
|
|
$output = array();
|
|
|
|
if ($type !== null && $idNum === null) {
|
|
return $output;
|
|
}
|
|
|
|
//Get the result
|
|
$liendocM = new Application_Model_JoLiensDoc();
|
|
try {
|
|
if ($idNum === null) {
|
|
$sql = $liendocM->select()
|
|
->where('id=?', $id)
|
|
->where('dateSuppr=?', '0000-00-00 00:00:00');
|
|
} else {
|
|
$sql = $liendocM->select()
|
|
->where('idNum=?', $idNum)
|
|
->where('idType=?', $type)
|
|
->where('dateSuppr=?', '0000-00-00 00:00:00');
|
|
}
|
|
$sql->order('dateDocRef DESC');
|
|
$rowset = $liendocM->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());
|
|
}
|
|
}
|
|
|
|
if ( $rowset->count()>0 ) {
|
|
|
|
foreach ( $rowset as $item ) {
|
|
$struct = new LienDoc();
|
|
$struct->id = $item->id;
|
|
$struct->perimetre = $item->periDoc;
|
|
$params = explode('-', $item->docRef);
|
|
switch($params[0]) {
|
|
case 'INTERNE' :
|
|
$tabLabel = array(
|
|
'CA'=>"Comptes Annuels",
|
|
'CC'=>"Comptes Consolidés",
|
|
'DR'=>"Document de référence",
|
|
'RA'=>"Rapport Annuel ou d'Activité",
|
|
'RS'=>"Rapport Semestriel",
|
|
'RG'=>"Rapport de gestion",
|
|
'RF'=>"Rapport financier",
|
|
'OR'=>"Organigramme",
|
|
'AP'=>"Article de presse",
|
|
'AC'=>"Acte",
|
|
'ST'=>"Statuts",
|
|
'DW'=>"Document Web/Internet",
|
|
);
|
|
$dateFormat = DateTime::createFromFormat('Ymd', $params[3]);
|
|
if ($dateFormat === false) {
|
|
$struct->label = $tabLabel[$params[2]].' ( - )';
|
|
} else {
|
|
$struct->label = $tabLabel[$params[2]].' ('.$dateFormat->format('d/m/Y').')';
|
|
}
|
|
$struct->url = $item->docRef.'.pdf';
|
|
break;
|
|
case 'GREFFE' :
|
|
$struct->label = $item->docRef;
|
|
$struct->url = $item->docRef;
|
|
//@todo
|
|
break;
|
|
}
|
|
|
|
$struct->date = $item->dateDocRef;
|
|
$output[] = $struct;
|
|
}
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Définition d'un document attaché à un lien
|
|
* @param string $infos
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function setLienDoc($infos, $id=null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$dataDoc = json_decode($infos, true);
|
|
|
|
$docM = new Application_Model_JoLiensDoc();
|
|
|
|
//Insert
|
|
if ($id===null) {
|
|
|
|
$dataDoc = array_merge($dataDoc, array(
|
|
'idInsert' => $this->User->id,
|
|
'dateInsert' => date('YmdHis'))
|
|
);
|
|
|
|
try {
|
|
$id = $docM->insert($dataDoc);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
//Update
|
|
else {
|
|
|
|
$dataDoc = array_merge($dataDoc, array(
|
|
'idSuppr' => $this->User->id,
|
|
'dateSuppr' => date('YmdHis'),
|
|
));
|
|
|
|
try {
|
|
$id = $docM->update($dataDoc, 'id = '.$id);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
|
|
/**
|
|
* Recherche de fiche lien dans le référentiel
|
|
* @param string $query
|
|
* @param string $type null|siren|identifiant|id|special
|
|
* @throws SoapFault
|
|
* @return SearchLienRef[]
|
|
*/
|
|
public function searchLienRef($query, $type = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
|
$sql = $db->select()->from(
|
|
array('l' => 'jo.liensRef'),
|
|
array(
|
|
'id', 'siren', 'actif', 'RS',
|
|
'nom', 'prenom', 'nom_usage', 'naissance_date', 'nat', 'adresse_cp', 'adresse_ville'
|
|
)
|
|
);
|
|
|
|
if ( $type == 'siren' ) {
|
|
|
|
$queries = explode(' ', $query);
|
|
$sql->joinLeft(array('p' => 'jo.tabPays'), 'p.codPays3 = l.adresse_pays', array('codPays3','libPays'));
|
|
$sql->where("l.siren=?", $queries[0]);
|
|
|
|
} elseif ( $type == 'isin' ) {
|
|
|
|
$queries = explode(' ', $query);
|
|
$sql->joinLeft(array('p' => 'jo.tabPays'), 'p.codPays3 = l.adresse_pays', array('codPays3','libPays'));
|
|
$sql->where("l.isin=?", $queries[0]);
|
|
|
|
}
|
|
// Identifiant Nationnaux
|
|
elseif ( $type == 'identifiant' ) {
|
|
|
|
$queries = explode(' ', $query);
|
|
$sql->joinLeft(array('p' => 'jo.tabPays'), 'p.codPays3 = l.adresse_pays', array('codPays3','libPays'));
|
|
$sql->where("l.idLoc1Num=?", $queries[0]);
|
|
|
|
}
|
|
// Identifiant interne
|
|
elseif ( $type == 'id' ) {
|
|
|
|
$sql->joinLeft(array('p' => 'jo.tabPays'), 'p.codPays3 = l.adresse_pays', array('codPays3','libPays'));
|
|
$sql->where("l.id=?", $query);
|
|
|
|
}
|
|
// Structure spécial
|
|
elseif ( $type == 'special' ) {
|
|
|
|
$queries = explode(' ', $query);
|
|
if (count($queries)>0) {
|
|
$where = '';
|
|
$i = 0;
|
|
foreach ($queries as $item) {
|
|
if (strlen($item)>2) {
|
|
$where.= 'LIKE "%'.strtolower($item).'%"';
|
|
}
|
|
$i++;
|
|
if (count($queries) > $i){
|
|
$where.= ' OR ';
|
|
}
|
|
}
|
|
$sql->where("(l.RS ".$where.") OR (l.nom ".$where.")");
|
|
$sql->where('l.id<1000');
|
|
}
|
|
|
|
}
|
|
// Recherche par nom
|
|
else {
|
|
|
|
$pos = strrpos($query, ',');
|
|
if ($pos !== false) {
|
|
$country = trim(substr($query, $pos+1));
|
|
$query = trim(substr($query, 0, $pos));
|
|
}
|
|
|
|
$sql->joinLeft(array('p' => 'jo.tabPays'), 'p.codPays3 = l.adresse_pays', array('codPays3','libPays'));
|
|
$sql->where('MATCH (l.RS, l.nom, l.prenom) AGAINST ("'.strtolower($query).'" IN NATURAL LANGUAGE MODE)');
|
|
$sql->where('l.id>=1000');
|
|
|
|
if ( !empty($country) ) {
|
|
$sql->where('l.adresse_pays=?', $country);
|
|
}
|
|
|
|
}
|
|
|
|
$sql->where("l.dateSuppr='0000-00-00 00:00:00'");
|
|
$sql->limit(20);
|
|
|
|
try {
|
|
$result = $db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$output = array();
|
|
if (count($result>0)) {
|
|
foreach($result as $item) {
|
|
$tmp = new SearchLienRef();
|
|
$tmp->id = $item->id;
|
|
|
|
//Personne Morale
|
|
if ($item->siren!='') {
|
|
$lib = $item->RS.', '.str_pad($item->siren, 9, '0', STR_PAD_LEFT);
|
|
} else {
|
|
$lib = $item->RS.', '.$item->adresse_cp.' '.$item->adresse_ville.', '.$item->libPays;
|
|
}
|
|
|
|
//Personne Physique
|
|
if ( $item->nom != '' ) {
|
|
$lib = ' '.$item->nom.' '.$item->prenom.', ';
|
|
if ( $item->nom_usage != '' ) {
|
|
$lib.= $item->nom_usage.', ';
|
|
}
|
|
$lib.= $item->naissance_date.', '.$item->nat;
|
|
if ( intval($item->siren) ) {
|
|
$lib.= ' ('.$item->siren.')';
|
|
}
|
|
}
|
|
|
|
if ($item->actif!=1) {
|
|
$lib.= ' (inactif)';
|
|
}
|
|
|
|
$tmp->lib = $lib;
|
|
$output[] = $tmp;
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Change siren for a registered mark
|
|
* @param int $id
|
|
* Registered mark ID
|
|
* @param string $siren
|
|
* Siren to affect
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function dupliqueMarque($id, $siren)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$idUser = $this->User->id;
|
|
|
|
$data = array(
|
|
'sirenDeposant' => $siren,
|
|
'sirenValide' => 2,
|
|
'idSirenage' => $idUser,
|
|
'dateUpdate' => date('YmdHis')
|
|
);
|
|
|
|
try {
|
|
$marqueM = new Application_Model_BopiMarques();
|
|
$result = $marqueM->update($data, 'id='.$id);
|
|
} catch (Zend_Db_Adapter_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
} catch (Zend_Exception $e) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Bourse
|
|
* @param string $isin
|
|
* @param string $infos
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function setBourse($isin, $infos)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if (strlen($isin)>12) {
|
|
throw new SoapFault('ERR', 'Code Isin incorrect.');
|
|
}
|
|
|
|
$data = json_decode($infos, true);
|
|
|
|
if (strlen(trim($isin))) {
|
|
$iBourse = new Metier_Partenaires_MBourse();
|
|
if (!$iBourse->isIsin($isin)) {
|
|
throw new SoapFault('ERR', 'Code Isin incorrect.');
|
|
}
|
|
}
|
|
|
|
$bourseM = new Application_Model_Sdv1BourseIsin();
|
|
|
|
//Check if exist
|
|
$sql = $bourseM->select()->where('code_isin=?',$isin);
|
|
$result = $bourseM->fetchAll($sql);
|
|
|
|
//Insert
|
|
if ($result->count()==0) {
|
|
|
|
$data = array_merge($data, array(
|
|
'dateInsert' => date('YmdHis'),
|
|
));
|
|
|
|
try {
|
|
$id = $bourseM->insert($data);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
//Update
|
|
else {
|
|
|
|
try {
|
|
$id = $bourseM->update($data, array('code_isin = ? ' => $isin));
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient!=1) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
} else {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* Informations boursières pour la saisie
|
|
* @param string $isin
|
|
* @throws SoapFault
|
|
* @return string
|
|
*/
|
|
public function getBourse($isin)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if (strlen($isin)>12) {
|
|
throw new SoapFault('ERR', 'Code Isin incorrect.');
|
|
}
|
|
|
|
$bourseM = new Application_Model_Sdv1BourseIsin();
|
|
$sql = $bourseM->select()->where('code_isin=?', $isin);
|
|
$result = $bourseM->fetchRow($sql);
|
|
if ( $result===null ) {
|
|
throw new SoapFault('MSG', 'Aucun résultat');
|
|
}
|
|
|
|
return json_encode($result->toArray());
|
|
}
|
|
|
|
/**
|
|
* LienRef Fusion or Move LienRef
|
|
* @param string $action fusion|moveact|movepar
|
|
* @param int $idLien
|
|
* Identifiant du lien entre idPar et idAct
|
|
* @param int $id
|
|
* Identifiant à affecter (idPar ou idAct)
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setLienChange($action, $idLien, $id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if (empty($action)) {
|
|
throw new SoapFault('ERR', "action");
|
|
}
|
|
|
|
$lienM = new Application_Model_JoLiens();
|
|
|
|
//Fusion :
|
|
if ($action=='fusion')
|
|
{
|
|
//Ecraser les actionnaires avec l'ancien id
|
|
$lienM->update(
|
|
array('idAct'=>$idLien, 'idUpdate'=>$this->User->id),
|
|
'idAct='.$id);
|
|
//Ecraser les participations avec l'ancien id
|
|
$lienM->update(
|
|
array('idPar'=>$idLien, 'idUpdate'=>$this->User->id),
|
|
'idPar='.$id);
|
|
|
|
//Supprimer la fiche
|
|
$lienrefM = new Application_Model_JoLiensRef();
|
|
$lienM->update(
|
|
array('dateSuppr'=>date('Ymd'), 'idSuppr'=>$this->User->id),
|
|
'id='.$id);
|
|
|
|
return true;
|
|
|
|
}
|
|
//Move actionnaire to a new parent
|
|
elseif ($action=='moveact')
|
|
{
|
|
try {
|
|
$result = $lienM->update(array('idPar'=>$id, 'idUpdate'=>$this->User->id),
|
|
'id='.$idLien);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ($result) return true;
|
|
}
|
|
//Move participation to a new parent
|
|
elseif ($action=='movepar')
|
|
{
|
|
try {
|
|
$result = $lienM->update(array('idAct'=>$id, 'idUpdate'=>$this->User->id),
|
|
'id='.$idLien);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
if ($result) return true;
|
|
}
|
|
//Move active participations if TUP and Fusion selected
|
|
elseif ($action=='tupfusion')
|
|
{
|
|
try {
|
|
$result = $lienM->update(array('idAct'=>$id, 'idUpdate'=>$this->User->id),
|
|
"idAct=$idLien AND actif=1 AND dateSuppr='0000-00-00 00:00:00'");
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
if ($result) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Position cut-off pour le calcul des scores
|
|
* @param string $infos
|
|
* json_encode array with this values
|
|
* siren
|
|
* encours
|
|
* scoreSolv
|
|
* scoreDir
|
|
* scoreConf
|
|
* remarque
|
|
* paiement
|
|
* @param boolean $delete
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function setScoreCutoff($infos, $delete = false)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if (null === $delete) {
|
|
$delete = false;
|
|
}
|
|
|
|
$data = json_decode($infos, true);
|
|
|
|
//if profil = score (20), use this table to convert
|
|
if ( $this->User->typeScore == 20 ) {
|
|
$convert20to100 = array(
|
|
0 => 0,
|
|
1 => 19,
|
|
2 => 29,
|
|
3 => 34,
|
|
4 => 35,
|
|
5 => 38,
|
|
6 => 40,
|
|
7 => 44,
|
|
8 => 45,
|
|
9 => 49,
|
|
10 => 50,
|
|
11 => 54,
|
|
12 => 56,
|
|
13 => 59,
|
|
14 => 61,
|
|
15 => 64,
|
|
16 => 68,
|
|
17 => 72,
|
|
18 => 79,
|
|
19 => 80,
|
|
20 => 90,
|
|
);
|
|
$data['scoreSolv'] = $convert20to100[$data['scoreSolv']];
|
|
$data['scoreDir'] = $convert20to100[$data['scoreDir']];
|
|
$data['scoreConf'] = $convert20to100[$data['scoreConf']];
|
|
}
|
|
|
|
$cutoffM = new Application_Model_JoScoresCutoff();
|
|
$sql = $cutoffM->select()->where('siren=?', $data['siren']);
|
|
$row = $cutoffM->fetchRow($sql);
|
|
|
|
//Historisation
|
|
if ( null !== $row ) {
|
|
$mvtM = new Application_Model_JoScoresCutoffMvt();
|
|
$backupData = $row->toArray();
|
|
unset($backupData['dateUpdate']);
|
|
$backupData = array_merge($backupData, array(
|
|
'idMvt' => $this->User->id,
|
|
'dateMvt'=>date('YmdHis')
|
|
));
|
|
|
|
try {
|
|
$mvtM->insert($backupData);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$result = $cutoffM->delete('siren='.$data['siren']);
|
|
}
|
|
|
|
if ( !$delete ) {
|
|
//Insertion
|
|
$data = array_merge($data, array(
|
|
'idInsert' => $this->User->id,
|
|
'dateInsert'=>date('YmdHis')
|
|
));
|
|
try {
|
|
$result = $cutoffM->insert($data);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
//Mise en surveillance
|
|
if ($result>0 && !empty($this->User->email)) {
|
|
$iInsee = new Metier_Insee_MInsee();
|
|
$tabIdentite = $iInsee->getIdentiteLight($data['siren']);
|
|
$data = array(
|
|
'source' => 'score',
|
|
'login' => $this->User->login,
|
|
'email' => $this->User->email,
|
|
'siren' => $data['siren'],
|
|
'nic' => 0,
|
|
'ref' => 'CUTOFF',
|
|
'encoursClient' => 0,
|
|
'rs' => $tabIdentite['Nom'],
|
|
'cp' => $tabIdentite['CP'],
|
|
'ville' => $tabIdentite['Ville'],
|
|
'dateAjout'=>date('Y-m-d'),
|
|
'dateSuppr'=>0,
|
|
);
|
|
$iDb = new Metier_Util_Db();
|
|
$iDb->insert('surveillances_site', $data);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Get cutoff on a SIREN
|
|
* @param string $siren
|
|
* @return mixed
|
|
*/
|
|
public function getScoreCutoff($siren)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$cutoffM = new Application_Model_JoScoresCutoff();
|
|
$sql = $cutoffM->select()->where('siren=?', $siren);
|
|
$row = $cutoffM->fetchRow($sql);
|
|
$result = false;
|
|
if ( null !== $row ) {
|
|
$scoreSolv = intval($row->scoreSolv);
|
|
$scoreDir = intval($row->scoreDir);
|
|
$scoreConf = intval($row->scoreConf);
|
|
if ( $this->User->typeScore==20 ) {
|
|
$convert100to20 = array(
|
|
0 => 0,
|
|
19 => 1,
|
|
29 => 2,
|
|
34 => 3,
|
|
35 => 4,
|
|
38 => 5,
|
|
40 => 6,
|
|
44 => 7,
|
|
45 => 8,
|
|
49 => 9,
|
|
50 => 10,
|
|
54 => 11,
|
|
56 => 12,
|
|
59 => 13,
|
|
61 => 14,
|
|
64 => 15,
|
|
68 => 16,
|
|
72 => 17,
|
|
79 => 18,
|
|
80 => 19,
|
|
90 => 20,
|
|
);
|
|
$scoreSolv = $convert100to20[$scoreSolv];
|
|
$scoreDir = $convert100to20[$scoreDir];
|
|
$scoreConf = $convert100to20[$scoreConf];
|
|
}
|
|
$result = json_encode(array(
|
|
'siren' => $row->siren,
|
|
'encours' => $row->encours,
|
|
'scoreSolv' => $scoreSolv,
|
|
'scoreDir' => $scoreDir,
|
|
'scoreConf' => $scoreConf,
|
|
'remarque' => $row->remarque,
|
|
'paiement' => $row->paiement,
|
|
'dateInsert' => $row->dateInsert,
|
|
'dateUpdate' => $row->dateUpdate,
|
|
));
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Ajouter, modifier, supprimer le dirigeant opérationnel
|
|
* @param string $infos
|
|
* @param string $mode
|
|
* @param int $id
|
|
* @return mixed
|
|
*/
|
|
public function setDirigeantsOp($infos, $mode, $id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$dirOp = new Application_Model_Sdv1DirigeantsOp();
|
|
|
|
$checkDel = ' AND dateSuppr="0000-00-00 00:00:00.000000"';
|
|
$where = "id=$id".$checkDel;
|
|
$userId = $this->User->id;
|
|
$dataRef = json_decode($infos, true);
|
|
|
|
$tabRet=array(
|
|
'siren' => $dataRef['siren'],
|
|
'nic' => $dataRef['nic'],
|
|
'civ' => $dataRef['civilite'],
|
|
'nom' => strtoupper($dataRef['nom']),
|
|
'prenom' => ucfirst(strtolower($dataRef['prenom'])),
|
|
'nom_usage' => $dataRef['nom_usage'],
|
|
'dateNais' => $dataRef['dateNais'],
|
|
'lieuNais' => $dataRef['lieuNais'],
|
|
'codFct' => $dataRef['codFct'],
|
|
'tel' => $dataRef['tel'],
|
|
'fax' => $dataRef['fax'],
|
|
'email' => $dataRef['email'],
|
|
);
|
|
|
|
switch($mode) {
|
|
case 'add':
|
|
$tabRet['dateInsert'] = date('Y-m-d H:i:s');
|
|
$tabRet['idInsert'] = $userId;
|
|
try {
|
|
$result = $dirOp->insert($tabRet);
|
|
} catch (Zend_Exception $e) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
return $result;
|
|
|
|
case 'edit':
|
|
$tabRet['idUpdate'] = $userId;
|
|
try {
|
|
$result = $dirOp->update($tabRet, $where);
|
|
} catch (Zend_Exception $e) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
return $result;
|
|
|
|
case 'del':
|
|
$tabRet = array(
|
|
'dateSuppr' => date('Y-m-d H:i:s'),
|
|
'idSuppr' => $userId
|
|
);
|
|
try {
|
|
$result = $dirOp->update($tabRet, $where);
|
|
} catch (Zend_Exception $e) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
return $result;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set geocode from web application
|
|
* @param string $companyId
|
|
* @param string $type
|
|
* @param string $data
|
|
* JSON string containing formatted data
|
|
* source, lat, lng, alt, address, precis
|
|
* @param string $override
|
|
* @throws SoapFault
|
|
* @return int
|
|
*/
|
|
public function setGeoCode($companyId, $type = null, $data, $override = false)
|
|
{
|
|
$this->authenticate();
|
|
$siren = null;
|
|
|
|
// --- Identifiant SD : source + id
|
|
if ($type === null) {
|
|
|
|
}
|
|
// --- Siren
|
|
elseif (strtolower($type) == 'siren') {
|
|
if (strlen($companyId) != 14) {
|
|
throw new SoapFault('ERR', 'SIRET invalide.');
|
|
}
|
|
}
|
|
// Erreur
|
|
else {
|
|
throw new SoapFault('ERR', 'Type identifiant inconnu.');
|
|
}
|
|
|
|
// --- Lecture de l'adresse
|
|
try {
|
|
$etablissementM = new Application_Model_JoEtablissements();
|
|
$sql = $etablissementM->select(true)->columns(array(
|
|
'LPAD(adr_num,4,0) AS adr_num',
|
|
'adr_btq',
|
|
'adr_typeVoie',
|
|
'adr_libVoie',
|
|
'adr_comp',
|
|
'LPAD(adr_cp,5,0) AS adr_cp',
|
|
'adr_ville'
|
|
))->where('siren=?', substr($companyId, 0, 9))->where('nic=?', substr($companyId, 9, 5));
|
|
$result = $etablissementM->fetchRow($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
if ($result === null) {
|
|
return 0;
|
|
}
|
|
|
|
// --- Result from database
|
|
$AdresseNum = $result->adr_num;
|
|
$AdresseTypeVoie = $result->adr_typeVoie;
|
|
$AdresseLibVoie = $result->adr_libVoie;
|
|
$AdresseCP = $result->adr_cp;
|
|
$AdresseVille = $result->adr_ville;
|
|
|
|
$insee = new Metier_Insee_MInsee();
|
|
$AdresseTypeVoieLong = strtoupper($insee->getCodeVoie($AdresseTypeVoie));
|
|
|
|
// --- Format adress
|
|
$adressPrimary = trim(preg_replace('/ +/',' ', "$AdresseNum $AdresseTypeVoieLong $AdresseLibVoie"));
|
|
|
|
// --- Code Rivoli
|
|
$codeRivoli = '';
|
|
try {
|
|
$inseeidentiteM = new Application_Model_InseeIdentite();
|
|
$sql = $inseeidentiteM->select(true)
|
|
->columns(array('ADR_DEP', 'LPAD(ADR_COM,3,0) AS ADR_COM', 'CODEVOIE', 'ADR_TYPVOIE', 'ADR_LIBVOIE'))
|
|
->where('SIREN=?', substr($companyId, 0, 9))
|
|
->where('NIC=?', substr($companyId, 9, 5));
|
|
$result = $inseeidentiteM->fetchRow($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
if ($result !== null) {
|
|
if (empty($result->CODEVOIE)) {
|
|
$codeRivoli = $insee->getCodeVoieRivoli(
|
|
$result->ADR_DEP.$result->ADR_COM,
|
|
empty($result->ADR_TYPEVOIE) ? '' : $result->ADR_TYPEVOIE,
|
|
empty($result->ADR_LIBVOIE) ? '' : $result->ADR_LIBVOIE
|
|
);
|
|
} else {
|
|
$codeRivoli = $result->ADR_DEP.$result->ADR_COM.$result->CODEVOIE;
|
|
}
|
|
}
|
|
|
|
// --- Prepare geocoding
|
|
try {
|
|
$zonageM = new Application_Model_JoZonageXY();
|
|
$sql = $zonageM->select()
|
|
->where('address=?', $adressPrimary)
|
|
->where('adr_cp=?', $AdresseCP)
|
|
->where('adr_ville=?', $AdresseVille);
|
|
$result = $zonageM->fetchRow($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
if ($result === null) {
|
|
$tableModif = 'insert';
|
|
} else {
|
|
$tableModif = 'update';
|
|
}
|
|
|
|
$output = 0;
|
|
$data = json_decode($data);
|
|
if (!empty($data->lat) && !empty($data->lng)) {
|
|
$precision = 0;
|
|
$dataGeocode = array();
|
|
|
|
// --- Source Google
|
|
if ( strtolower($data->source) == 'google' ) {
|
|
switch($data->precis) {
|
|
/**
|
|
* Precise geocode for which we have location information accurate down to street address precision.
|
|
*/
|
|
case 'ROOFTOP':
|
|
$precision = 8;
|
|
break;
|
|
/**
|
|
* Approximation (usually on a road) interpolated between two precise points (such as intersections).
|
|
* Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.
|
|
*/
|
|
case 'RANGE_INTERPOLATED':
|
|
$precision = 7;
|
|
break;
|
|
/**
|
|
* Geometric center of a result such as a polyline (for example, a street) or polygon (region).
|
|
*/
|
|
case 'GEOMETRIC_CENTER':
|
|
$precision = 6;
|
|
break;
|
|
/**
|
|
* indicates that the returned result is approximate.
|
|
*/
|
|
case 'APPROXIMATE':
|
|
$precision = 4;
|
|
break;
|
|
}
|
|
|
|
$lambert = geos2lambert93($data->lat, $data->lng);
|
|
$dataGeocode = array(
|
|
'address' => $adressPrimary,
|
|
'adr_cp' => $AdresseCP,
|
|
'adr_ville' => $AdresseVille,
|
|
'adrNum' => $AdresseNum,
|
|
'adrIndRep' => '',
|
|
'adrTypeVoie' => $AdresseTypeVoie,
|
|
'adrLibVoie' => $AdresseLibVoie,
|
|
'rivoli' => $codeRivoli,
|
|
'adresseValidee' => urldecode($data->address),
|
|
'lat' => $data->lat,
|
|
'lon' => $data->lng,
|
|
'l93_x' => $lambert['x_93'],
|
|
'l93_y' => $lambert['y_93'],
|
|
'alt' => intval($data->alt),
|
|
'precis' => $precision,
|
|
'source' => 'Google',
|
|
);
|
|
}
|
|
|
|
if (count($dataGeocode) > 0) {
|
|
try {
|
|
if ($tableModif == 'insert') {
|
|
$dataGeocode['dateInsert'] = date('YmdHis');
|
|
$output = $zonageM->insert($dataGeocode);
|
|
} else {
|
|
$output = $zonageM->update($dataGeocode, array(
|
|
'address=?' => $adressPrimary,
|
|
'adr_cp=?' => $AdresseCP,
|
|
'adr_ville=?' => $AdresseVille,
|
|
));
|
|
}
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
protected function getLienUser($id, $type = null)
|
|
{
|
|
$this->authenticate();
|
|
//InsertId
|
|
//InsertUser
|
|
//InsertDate
|
|
//UpdateId
|
|
//UpdateUser
|
|
//UpdateDate
|
|
}
|
|
|
|
protected function getLienRefUser($id, $type = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//InsertId
|
|
//InsertUser
|
|
//InsertDate
|
|
//UpdateId
|
|
//UpdateUser
|
|
//UpdateDate
|
|
}
|
|
|
|
} |