2013-11-05 11:18:30 +00:00
< ? php
require_once 'WsScore/WsScore.php' ;
require_once realpath ( dirname ( __FILE__ )) . '/Types.php' ;
class Saisie extends WsScore
{
/**
* 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 ();
debugLog ( 'I' , " Recherche de Mandataires ' $nom ' (Dep= $cpDep ) " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
$iInsee = new 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 MBodacc ();
$iInsee = new 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 WDB ();
$tabInfos = json_decode ( $infos , true );
$tabIdentite = $tabInfos [ 'identite' ];
$tabJugement = $tabInfos [ 'jugement' ];
$tabActio = $tabInfos [ 'actionnaire' ];
$tabParti = $tabInfos [ 'participation' ];
$tabScores = $tabInfos [ 'score' ];
// 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' ], '"\'./- ,\*#()' , ' ' ))),
);
/** @todo non traitées : [capital_mt] => 335400, [capital_dev] => EUR **/
if ( ! $iDb -> update ( 'infos_entrep' , $tabUpdate , " siren=' $siren ' " ) ){
if ( ! $iDb -> insert ( 'infos_entrep' , array_merge ( array ( 'siren' => $siren ), $tabUpdate ))){
$error -> errnum = 1 ;
$error -> errmsg = 'Mise a jour impossible' ;
$output = new SetInfosEntrepReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
}
// Fin mise à jour identité
// Opposition INSEE
if ( $tabIdentite [ 'moisOppositionInsee' ] > 0 &&
$tabIdentite [ 'moisOppositionInsee' ] <= ( date ( 'Ym' ) * 1 ) ){
$iDb2 = new WDB ( 'insee' );
if ( ! $iDb2 -> insert ( 'insee_nondiff' , array ( 'siren' => $siren , 'insEVE' => 795 , 'mois' => $tabIdentite [ 'moisOppositionInsee' ])) ){
if ( $iDb2 -> getLastErrorNum () <> 1062 )
@ sendMail ( 'production@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " ERREUR setInfosEntrep pour $siren " , " Erreur lors de l'inscription à la liste des oppositions de la sphère commerciale INSEE pour $siren au mois de " . $tabIdentite [ 'moisOppositionInsee' ] . " : " . EOL . print_r ( $tabIdentite , true ) . EOL . $iDb2 -> getLastError ());
}
}
// Fin opposition INSEE
// Refus d'inscription au RCS
if ( isset ( $tabIdentite [ 'moisRefusRCS' ]) && $tabIdentite [ 'moisRefusRCS' ] > 0
&& $tabIdentite [ 'moisRefusRCS' ] <= ( date ( 'Ym' ) * 1 )) {
$iInsee = new MInsee ();
$entrep = $iInsee -> getIdentiteLight ( $siren );
if ( $nic < 10 ) $nic = $entrep [ 'Nic' ];
$cj1 = substr ( $entrep [ 'FJ' ], 0 , 1 );
$iDb2 = new WDB ( 'insee' );
/** Insertion dans la tables des exclusions **/
$tabInsert = array (
'siren' => $siren ,
'nic' => $nic ,
'idSaisie' => $this -> tabInfoUser [ 'id' ],
'cj1' => $cj1 ,
'insEVE' => 'RCS' ,
'mois' => $tabIdentite [ 'moisRefusRCS' ],
);
if ( ! $iDb2 -> insert ( 'insee_nondiff' , $tabInsert ))
if ( $iDb2 -> getLastErrorNum () <> 1062 )
@ sendMail ( 'production@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " ERREUR setInfosEntrep pour $siren " , " Erreur lors de l'inscription à la liste des refus d'enregistrement A au RCS pour $siren au mois de " . $tabIdentite [ 'moisRefusRCS' ] . " : " . EOL . print_r ( $tabInsert , true ) . EOL . print_r ( $tabIdentite , true ) . EOL . $iDb2 -> getLastError ());
/** 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_even' , $tabInsert ))
@ sendMail ( 'production@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " ERREUR setInfosEntrep pour $siren " , " Erreur lors de l'inscription à la liste des refus d'enregistrement B au RCS pour $siren au mois de " . $tabIdentite [ 'moisOppositionInsee' ] . " : " . EOL . print_r ( $tabInsert , true ) . EOL . print_r ( $tabIdentite , true ) . EOL . $iDb2 -> getLastError ());
}
// 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 );
if ( ! $iDb -> update ( 'tabAdrDom' , $tabUpdate , " siren= $siren " ))
@ sendMail ( 'production@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " ERREUR setInfosEntrep pour $siren " , " Erreur lors de la suppression du marqueur de domiciliation pour $siren : " . EOL . print_r ( $tabUpdate , true ) . EOL . $iDb -> getLastError ());
}
}
// 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 ( 'scores_cutoff' , $tabUpdate , " siren= $siren " ) ){
if ( ! $iDb -> insert ( 'scores_cutoff' , array_merge ( array (
'siren' => $siren ,
'dateInsert' => date ( 'Ymd' ) ), $tabUpdate )) ){
@ sendMail ( 'production@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " ERREUR setInfosEntrep pour $siren " , print_r ( $tabScores , true ) . EOL . $iDb -> getLastError ());
}
}
}
// 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 = WDate :: 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' ]) ? '' :
WDate :: dateT ( 'd/m/Y' , 'Y-m-d' , trim ( $tabJugement [ 'datePaie' ])),
'dateEffetFinP' => empty ( $tabJugement [ 'dateFinPeriode' ]) ? '' :
WDate :: dateT ( 'd/m/Y' , 'Y-m-d' , trim ( $tabJugement [ 'dateFinPeriode' ])),
'tribunal' => trim ( $tabJugement [ 'tribunal' ]),
'montant' => $montant ,
'actionsNb' => $actionsNb ,
'inter1type' => 'A' ,
'inter1id' => $idAdmin ,
'inter1nom' => utf8_encode ( $iInsee -> getMandatairesParId ( $idAdmin )),
'inter2type' => 'M' ,
'inter2id' => $idMand ,
'inter2nom' => utf8_encode ( $iInsee -> getMandatairesParId ( $idMand )),
'inter3type' => 'O' ,
'inter3id' => $idOppo ,
'inter3nom' => utf8_encode ( $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 -> tabInfoUser [ 'id' ],
'parutionIdJal' => $numJal ,
'parutionNum' => $tabJugement [ 'numParution' ],
);
$dateJuge = WDate :: 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 ( 'annonces' , array_merge ( $tabInsert , array ( 'dateInsert' => date ( 'YmdHis' ))), true ) ){
if ( ! $iDb -> update ( '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 = WDate :: 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 ( 'liens' , 'count(*)' ,
" Siren1= $siren AND (Siren2= $siren2 OR (RaisonSociale=' $nom ' AND Pays=' $pays ')) " );
if ( $res [ 0 ][ 0 ] > 0 ) {
if ( ! $iDb -> update ( '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 ( '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 ( 'liens' , 'count(*)' , " Siren1= $siren2 AND (Siren2= $siren OR (RaisonSociale=' $nom2 ' AND Pays=' $pays2 ')) " );
if ( $res [ 0 ][ 0 ] > 0 ) {
if ( ! $iDb -> update ( '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 ( '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 = WDate :: 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 ( 'liens' , 'count(*)' , " Siren1= $siren AND (Siren2= $siren2 OR (RaisonSociale=' $nom ' AND Pays=' $pays ')) " );
if ( $res [ 0 ][ 0 ] > 0 ) {
if ( ! $iDb -> update ( '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 ( '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 ( 'liens' , 'count(*)' , " Siren1= $siren2 AND (Siren2= $siren OR (RaisonSociale=' $nom2 ' AND Pays=' $pays2 ')) " );
if ( $res [ 0 ][ 0 ] > 0 ) {
if ( ! $iDb -> update ( '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 ( '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 ;
}
/**
* Met a jour les informations sur un mandataire
* @ param SetInfosMandataire $infos Informations sur le mandataire à créer ou à ajouter ( ajout si id absent )
* @ return SetMandataireReturn
*/
public function setMandataire ( SetInfosMandataire $infos )
{
$this -> authenticate ();
//Initialisation
$error = new ErrorType ();
$result = true ;
$iDb = new WDB ();
//$infos = serialize($tabInfos);
debugLog ( 'I' , " Ajout/MAJ de mandaitaire " . print_r ( $infos , 1 ) . " demandée " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
$type = substr ( strtoupper ( $infos -> type ), 0 , 1 );
$stag = substr ( strtoupper ( $infos -> type ), 1 , 1 );
if ( $stag == 'S' ) {
$stag = 1 ;
} else {
$stag = 0 ;
}
if ( $type == 'A' || $type == 'H' || $type == 'M' || $type == 'V' ||
$type == 'N' || $type == '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 -> tabInfoUser [ 'id' ],
);
}
$id = str_replace ( 'm' , '' , '' . $infos -> id ) * 1 ;
if ( intval ( $id ) != 0 ) {
// MAJ
if ( ! $iDb -> update ( 'tabMandataires' , $tabUpdate , " id= $id " , true )) {
$error -> errnum = 1 ;
$error -> errmsg = 'Mise a jour impossible' ;
$result = false ;
}
} else {
// Insertion
if ( ! $iDb -> insert ( 'tabMandataires' , array_merge ( $tabUpdate , array ( 'dateInsert' => date ( 'YmdHis' ))), true )) {
$error -> errnum = 1 ;
$error -> errmsg = 'Insertion impossible' ;
$result = false ;
}
}
$output = new SetMandataireReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
/**
* 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 WDB ();
$idAnn = preg_replace ( '/^0\./' , '' , '' . $idAnn ) * 1 ;
if ( $idAnn > 0 )
{
if ( $iDb -> update ( 'annonces' , array (
'dateSuppr' => date ( 'YmdHis' ),
'idSuppr' => $this -> tabInfoUser [ 'id' ]),
" id= $idAnn " , false ))
{
debugLog ( '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' ;
debugLog ( '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 ();
require_once 'Metier/insee/classMInsee.php' ;
$iInsee = new 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 MInsee ();
$error = new ErrorType ();
$trib = serialize ( $codeTribunal );
debugLog ( '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 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 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 WDB ();
$idAnn = intval ( preg_replace ( '/^0\./' , '' , '' . $idAnn ));
if ( $idAnn > 0 && $siren > 1000 ){
$res = $iDb -> select ( '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 ( 'annonces' , $annonce , false )) {
debugLog ( 'I' , " Duplication de l'annonce collectée n° $idAnn sur $siret " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
$result = 1 ;
} else {
debugLog ( '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 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' ];
//@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' ];
debugLog ( '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' => WDate :: 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 -> tabInfoUser [ '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 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 WDB ();
switch ( $source )
{
case 0 :
$idAnn = preg_replace ( '/^0\./' , '' , '' . $idAnn ) * 1 ;
$table = 'annonces' ;
break ;
case 1 :
if ( intval ( $idAnn ) < 0 ){
$error -> errnum = 1 ;
$error -> errmsg = 'Code annonce Incorrect' ;
} else {
$strSql = " AND siren= $siren " ;
$table = '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 -> tabInfoUser [ 'id' ]),
" id= $idAnn $strSql " , false ))
{
debugLog ( 'I' , " Suppression de l'annonce en source $source n° $idAnn ( $siret ) " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
$error -> errnum = 0 ;
$error -> errmsg = '' ;
$result = true ;
} else {
debugLog ( '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 )
{
debugLog ( '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 WDB ();
$strSql = '' ;
switch ( $source )
{
//
case 0 :
$idAnn = preg_replace ( '/^0\./' , '' , '' . $idAnn ) * 1 ;
$table = '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 = 'bodacc_detail' ;
}
break ;
//Association
case 3 :
$table = 'asso' ;
break ;
//
case 2 :
//
case 4 :
//
default :
$error -> errnum = 1 ;
$error -> errmsg = 'Cas non géré' ;
break ;
}
if ( intval ( $idAnn ) > 0 ) {
$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 == 'asso' ){
//$annonce = $res[0];
$annonce [ 'siren' ] = $sirenOut ;
$annonce [ 'sirenValide' ] = 2 ;
$annonce [ 'dateUpdate' ] = date ( 'YmdHis' );
$annonce [ 'idSirenage' ] = $this -> tabInfoUser [ 'id' ];
$annonce [ 'nic' ] = $nicOut ;
if ( $nicOut > 0 ) $annonce [ 'nicValide' ] = 2 ;
if ( $iDb -> update ( $table , $annonce , " id= " . $idAnn , true , true )) {
debugLog ( '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 {
debugLog ( '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 == 'bodacc_detail' ) {
$annonce = $res [ 0 ];
$annonce [ 'siren' ] = $sirenOut ;
$annonce [ 'sirenValide' ] = 2 ;
$annonce [ 'dateInsert' ] = date ( 'YmdHis' );
$annonce [ 'idSirenage' ] = $this -> tabInfoUser [ 'id' ];
$annonce [ 'nic' ] = $nicOut ;
if ( $nicOut > 0 ) $annonce [ 'nicValide' ] = 2 ;
if ( $iDb -> insert ( $table , $annonce , true , true )) {
debugLog ( '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 -> tabInfoUser [ 'id' ],
'dateSuppr' => date ( 'YmdHis' ),
);
$iDb -> update ( $table , $data , " id= $idAnn $strSql " , true , true );
} else {
debugLog ( '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 == 'bodacc_detail' ) {
$annonce = $res [ 0 ];
$annonce [ 'siren' ] = $sirenOut ;
$annonce [ 'sirenValide' ] = 2 ;
$annonce [ 'dateInsert' ] = date ( 'YmdHis' );
$annonce [ 'idSirenage' ] = $this -> tabInfoUser [ 'id' ];
$annonce [ 'nic' ] = $nicOut ;
if ( $nicOut > 0 ) $annonce [ 'nicValide' ] = 2 ;
if ( $iDb -> insert ( $table , $annonce , true , true )) {
debugLog ( 'I' , " Duplication de l'annonce en source $source sur n° $idAnn (siretIn= $siretIn , siretOut= $siretOut ) " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
$result = true ;
} else {
debugLog ( '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 == 'annonces' ){
$annonce = $res [ 0 ];
// Suppression des zones inexistantes dans la table ou devant être vides
unset ( $annonce [ 'id' ]);
unset ( $annonce [ 'nic' ]);
$annonce [ 'idSaisie' ] = $this -> tabInfoUser [ 'id' ];
if ( $iDb -> insert ( $table , $annonce , true , true )) {
debugLog ( 'I' , " Duplication de l'annonce en source $source sur n° $idAnn (siretIn= $siretIn , siretOut= $siretOut ) " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
$result = true ;
} else {
debugLog ( '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 {
debugLog ( '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 WDB ( 'jo' );
$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 -> tabInfoUser [ 'id' ],
);
if ( $iDb -> update ( 'bodacc_detail' , $tabUpdate , " siren=' $siren ' AND id=' $id ' " )){
debugLog ( 'I' , " setAnnonceEven (siren= $siren , list= $list ) " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
return true ;
}
}
return false ;
}
2013-12-26 14:25:59 +00:00
/**
* Delete a contact
* @ param int $id
* @ throws SoapFault
* @ return int
*/
public function delContactEt ( $id )
{
try {
$telephonieM = new Application_Model_JoTelephonie ();
$data = array ( 'dateSuppr' );
$id = $telephonieM -> update ( $data , 'id=' . $id );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
return $id ;
}
2013-11-05 11:18:30 +00:00
/**
* Enregistre une information de contact
* @ param string $siret
2013-12-26 14:25:59 +00:00
* SIRET ou SIREN
2013-11-05 11:18:30 +00:00
* @ param string $type
2013-12-26 14:25:59 +00:00
* Type de l ' information ( tel | fax | mail | mob | web )
2013-11-05 11:18:30 +00:00
* @ param string $value
2013-12-26 14:25:59 +00:00
* Valeur
2013-11-05 11:18:30 +00:00
* @ param string $info
2013-12-26 14:25:59 +00:00
* Information complémentaire ( use for type " tel " as description )
* @ param int id
* Id ( only for editing )
2013-11-05 11:18:30 +00:00
* @ return int
2013-12-26 14:25:59 +00:00
* Retourne l 'identifiant de l' élément ou le nombre de ligne lors d ' un update
2013-11-05 11:18:30 +00:00
*/
2013-12-26 14:25:59 +00:00
public function setContactEt ( $siret , $type , $value , $info , $id = null )
2013-11-05 11:18:30 +00:00
{
$this -> authenticate ();
$idUtilisateur = $this -> tabInfoUser [ 'idUtilisateur' ];
//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 ( $nic , 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 'tel' :
break ;
}
$iInsee = new 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' ),
2013-12-26 14:25:59 +00:00
'typeTel' => $type ,
2013-11-05 11:18:30 +00:00
'infoTel' => $info ,
'telephone' => $value ,
2013-12-26 14:25:59 +00:00
'actif' => 1 ,
'partenaire' => 175 ,
2013-11-05 11:18:30 +00:00
'idUtilisateur' => $idUtilisateur ,
'dateInsert' => date ( 'YmdHis' ),
);
2013-12-26 14:25:59 +00:00
if ( $id === null ) {
try {
$telephonieM = new Application_Model_JoTelephonie ();
$id = $telephonieM -> insert ( $data );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
} else {
try {
$telephonieM = new Application_Model_JoTelephonie ();
$id = $telephonieM -> update ( $data , 'id=' . $id );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
}
return $id ;
}
/**
* Get a contact
* @ param int $id
* @ throws SoapFault
* @ return string
*/
public function getContactEt ( $id )
{
$this -> authenticate ();
$lienM = new Application_Model_JoTelephonie ();
2013-11-05 11:18:30 +00:00
try {
2013-12-26 14:25:59 +00:00
$row = $lienM -> find ( $id );
2013-11-05 11:18:30 +00:00
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
2013-12-26 14:25:59 +00:00
$result = $row -> current () -> toArray ();
return json_encode ( $result );
2013-11-05 11:18:30 +00:00
}
2013-12-26 14:25:59 +00:00
2013-11-05 11:18:30 +00:00
/**
* Saisie d ' un bilan
* @ param string $siren
* @ param BilanInfos $data
* @ param string $step ( normal | nocheck | onlycheck )
* @ return int
* @ throws SoapFault
*/
public function setBilan ( $siren , $data , $step = null )
{
$this -> authenticate ();
//Control input value
if ( strlen ( $siren ) != 9 ) {
$this -> sendError ( '1010' );
}
$intervalCalc = 10 ;
$tabPostes = array ();
//Control des valeurs
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 )
{
global $tabCtrl ;
require_once 'Metier/partenaires/classMBilans.php' ;
$tabFormules = array ();
//Parcourir les formules
foreach ( $tabCtrl [ $data -> typeBilan ] as $formule => $lib ) {
$posEgal = strpos ( $formule , '=' );
$partLeft = substr ( $formule , 0 , $posEgal );
preg_match_all ( '/([A-Z0-9]+|(\+|\-))/' , $partLeft , $matches );
$total = substr ( $formule , $posEgal + 1 );
$tabFormules [] = array (
'operation' => $matches [ 0 ],
'total' => $total ,
);
}
//Effectuer le calcul
if ( count ( $tabFormules ) > 0 ) {
foreach ( $tabFormules as $formule ) {
$checkPostes = array ();
//Réaliser le calcul
$calc = 0 ;
$signe = null ;
foreach ( $formule [ 'operation' ] as $operation ) {
if ( $operation == '-' ) {
$signe = '-' ;
} elseif ( $operation == '+' ) {
$signe = '+' ;
} else {
$checkPostes [] = $operation ;
//Vérification valeur poste
if ( ! array_key_exists ( $operation , $tabPostes ) ) {
$tabPostes [ $operation ] = 0 ;
}
//Calcul
if ( empty ( $signe ) ) {
$calc = $tabPostes [ $operation ];
} elseif ( $signe == '+' ) {
$calc += $tabPostes [ $operation ];
} elseif ( $signe == '-' ) {
$calc -= $tabPostes [ $operation ];
}
}
}
$checkPostes [] = $formule [ 'total' ];
//Effecteur la vérification avec le total
if ( ! array_key_exists ( $formule [ 'total' ], $tabPostes ) ) {
$total = 0 ;
} else {
$total = $tabPostes [ $formule [ 'total' ]];
}
if ( $calc != $total && ! ( $calc - $intervalCalc < $total && $calc + $intervalCalc > $total ) ) {
throw new SoapFault ( 'ERR' , join ( ';' , $checkPostes ));
}
}
}
2013-11-06 14:29:20 +00:00
} //End of Mathematic control
2013-11-05 11:18:30 +00:00
if ( $step == 'onlycheck' ) {
return 1 ;
} else {
try {
$bilansM = new Application_Model_JoBilans ();
$sql = $bilansM -> select ()
-> where ( 'siren=?' , $siren )
-> where ( 'dateExercice=?' , $data -> dateCloture )
-> where ( 'typeBilan=?' , $data -> typeBilan );
$row = $bilansM -> fetchRow ( $sql );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
2013-11-06 14:29:20 +00:00
$postesDiff = array ();
2013-11-05 11:18:30 +00:00
if ( $row !== null ) {
2013-11-06 14:29:20 +00:00
//Make the diff
$postesDiff = array_diff ( explode ( ';' , $data -> postes ), explode ( ';' , $row -> postes ));
2013-11-05 11:18:30 +00:00
//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 -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
//Define data
$dataToUpdate = array (
'dateProvPartenaire' => date ( 'Ymd' ),
'dateExercicePre' => $data -> dateCloturePre ,
'dureeExercice' => $data -> dureeMois ,
'dureeExercicePre' => $data -> dureeMoisPre ,
'monnaie' => 'EUR' ,
'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 -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
} else {
//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 -> tabInfoUser [ '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 -> tabInfoUser [ 'id' ],
'login' => $this -> tabInfoUser [ 'login' ],
'siren' => $siren ,
'dateExercice' => $data -> dateCloture ,
'typeBilan' => $data -> typeBilan ,
'dateAction' => date ( 'YmdHis' ),
2013-11-06 14:29:20 +00:00
'postesDiff' => implode ( ';' , $postesDiff ),
2013-11-05 11:18:30 +00:00
));
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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 -> tabInfoUser [ '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 -> tabInfoUser [ '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 -> tabInfoUser [ '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 );
}
2013-12-26 14:25:59 +00:00
$sql -> where ( 'actif=?' , 1 ) -> where ( 'dateSuppr=?' , '0000-00-00 00:00:00' );
2013-11-05 11:18:30 +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 -> tabInfoUser [ 'id' ],
'dateInsert' => date ( 'YmdHis' ),
));
try {
$id = $lienM -> insert ( $dataLien );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
}
//Mise à jour des infos
else {
2013-12-26 14:25:59 +00:00
if ( $dataLien [ 'motifUpdate' ] == " Erreur d'affiliation " ) {
2013-11-05 11:18:30 +00:00
$dataLien = array_merge ( $dataLien , array (
'idSuppr' => $this -> tabInfoUser [ 'id' ],
'dateSuppr' => date ( 'YmdHis' ),
));
} else {
$dataLien = array_merge ( $dataLien , array (
'idUpdate' => $this -> tabInfoUser [ '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 -> tabInfoUser [ '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 ;
$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 -> tabInfoUser [ 'id' ],
'dateInsert' => date ( 'YmdHis' ))
);
try {
$id = $refM -> insert ( $dataRef );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
}
//Update
else {
2013-12-26 14:25:59 +00:00
if ( array_key_exists ( 'delete' , $dataRef ) && $dataRef [ 'delete' ] == 1 ) {
2013-11-05 11:18:30 +00:00
2013-12-26 14:25:59 +00:00
$dataRef = array (
2013-11-05 11:18:30 +00:00
'idSuppr' => $this -> tabInfoUser [ 'id' ],
'dateSuppr' => date ( 'YmdHis' ),
2013-12-26 14:25:59 +00:00
);
2013-11-13 14:04:35 +00:00
2013-11-05 11:18:30 +00:00
try {
$id = $refM -> update ( $dataRef , 'id = ' . $id );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
} else {
$dataRef = array_merge ( $dataRef , array (
'idUpdate' => $this -> tabInfoUser [ 'id' ],
'dateUpdate' => date ( 'YmdHis' ),
));
try {
$id = $refM -> update ( $dataRef , 'id = ' . $id );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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 -> find ( $id );
$ouput = '' ;
if ( $row === null ) {
} else {
$output = json_encode ( $row -> current () -> 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 );
$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' ) -> limit ( 3 );
$rowset = $liendocM -> fetchAll ( $sql );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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 " ,
);
$struct -> label = $tabLabel [ $params [ 2 ]] . ' (' . WDate :: dateT ( 'Ymd' , 'd/m/Y' , $params [ 3 ]) . ')' ;
$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 -> tabInfoUser [ 'id' ],
'dateInsert' => date ( 'YmdHis' ))
);
try {
$id = $docM -> insert ( $dataDoc );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
}
//Update
else {
$dataDoc = array_merge ( $dataDoc , array (
'idSuppr' => $this -> tabInfoUser [ 'id' ],
'dateSuppr' => date ( 'YmdHis' ),
));
try {
$id = $docM -> update ( $dataDoc , 'id = ' . $id );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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' ));
if ( $type == 'siren' ) {
$queries = explode ( ' ' , $query );
$sql -> join ( array ( 'p' => 'jo.tabPays' ), 'p.codPays3 = l.adresse_pays' , array ( 'codPays3' , 'libPays' ));
$sql -> where ( " l.siren=? " , $queries [ 0 ]);
} elseif ( $type == 'identifiant' ) {
$queries = explode ( ' ' , $query );
$sql -> join ( array ( 'p' => 'jo.tabPays' ), 'p.codPays3 = l.adresse_pays' , array ( 'codPays3' , 'libPays' ));
$sql -> where ( " l.idLoc1Num=? " , $queries [ 0 ]);
} elseif ( $type == 'id' ) {
$sql -> join ( array ( 'p' => 'jo.tabPays' ), 'p.codPays3 = l.adresse_pays' , array ( 'codPays3' , 'libPays' ));
$sql -> where ( " l.id=? " , $query );
} 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' );
}
} else {
$sql -> join ( array ( 'p' => 'jo.tabPays' ), 'p.codPays3 = l.adresse_pays' , array ( 'codPays3' , 'libPays' ));
$pos = strrpos ( $query , ',' );
if ( $pos !== false ) {
$country = trim ( substr ( $query , $pos + 1 ));
$query = trim ( substr ( $query , 0 , $pos ));
}
$queries = explode ( ' ' , $query );
if ( count ( $queries ) > 0 ) {
$where = '' ;
$i = 0 ;
foreach ( $queries as $item ) {
if ( strlen ( $item ) > 2 ) {
$where = 'LIKE "%' . strtolower ( $item ) . '%"' ;
}
$i ++ ;
$sql -> where ( 'CONCAT_WS(" ", l.RS, l.nom, l.prenom) ' . $where );
}
$sql -> where ( 'l.id>=1000' );
}
if ( ! empty ( $country ) ) {
$sql -> where ( 'l.adresse_pays=?' , $country );
}
}
2013-11-13 14:04:35 +00:00
$sql -> where ( " l.dateSuppr='0000-00-00 00:00:00' " );
2013-11-05 11:18:30 +00:00
$sql -> limit ( 20 );
try {
$result = $db -> fetchAll ( $sql , null , Zend_Db :: FETCH_OBJ );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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 . ', ' . $item -> nom_usage . ', ' . $item -> naissance_date . ', ' . $item -> nat ;
}
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 -> tabInfoUser [ '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 -> tabInfoUser [ '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 );
$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 -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
}
//Update
else {
try {
$id = $bourseM -> update ( $data , 'code_isin = ' . $isin );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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 ();
$result = $bourseM -> find ( $isin ) -> current ();
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 -> tabInfoUser [ 'id' ]),
'idAct=' . $id );
//Ecraser les participations avec l'ancien id
$lienM -> update (
array ( 'idPar' => $idLien , 'idUpdate' => $this -> tabInfoUser [ 'id' ]),
'idPar=' . $id );
//Supprimer la fiche
$lienrefM = new Application_Model_JoLiensRef ();
$lienM -> update (
array ( 'dateSuppr' => date ( 'Ymd' ), 'idSuppr' => $this -> tabInfoUser [ 'id' ]),
'id=' . $id );
return true ;
}
//Move actionnaire to a new parent
elseif ( $action == 'moveact' )
{
try {
$result = $lienM -> update ( array ( 'idPar' => $id , 'idUpdate' => $this -> tabInfoUser [ 'id' ]),
'id=' . $idLien );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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 -> tabInfoUser [ 'id' ]),
'id=' . $idLien );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ '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
* @ 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 -> tabInfoUser [ '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 -> tabInfoUser [ 'id' ],
'dateMvt' => date ( 'YmdHis' )
));
try {
$mvtM -> insert ( $backupData );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] != 1 ) {
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
$cutoffM -> delete ( 'siren=' . $data [ 'siren' ]);
}
if ( ! $delete ) {
//Insertion
$data = array_merge ( $data , array (
'idInsert' => $this -> tabInfoUser [ 'id' ],
'dateInsert' => date ( 'YmdHis' )
));
try {
$result = $cutoffM -> insert ( $data );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> tabInfoUser [ 'idClient' ] == 1 ) {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
//Mise en surveillance
if ( $result > 0 && ! empty ( $this -> tabInfoUser [ 'email' ])) {
$iInsee = new MInsee ();
$tabIdentite = $iInsee -> getIdentiteLight ( $data [ 'siren' ]);
$data = array (
'source' => 'score' ,
'login' => $this -> tabInfoUser [ 'login' ],
'email' => $this -> tabInfoUser [ '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 WDB ( 'jo' );
$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 -> tabInfoUser [ '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 ,
'dateInsert' => $row -> dateInsert ,
'dateUpdate' => $row -> dateUpdate ,
));
}
return $result ;
}
}