308 lines
11 KiB
PHP
308 lines
11 KiB
PHP
<?php
|
|
ini_set('soap.wsdl_cache_enabled', 0);
|
|
ini_set('default_socket_timeout', 30);
|
|
|
|
class Metier_Partenaires_MAmabis
|
|
{
|
|
protected $client;
|
|
protected $iDb;
|
|
|
|
public function __construct($db = null)
|
|
{
|
|
if ( $db === null ) {
|
|
$this->iDb = new Metier_Util_Db();
|
|
} else {
|
|
$this->iDb = $db;
|
|
}
|
|
|
|
$this->client = new SoapClient(null, array(
|
|
'location' => 'http://sw2.amabis.com:5100/',
|
|
'uri' => 'http://www.amabis.com/ns.xsd',
|
|
'connection_timeout' => 2,
|
|
'soap_version' => SOAP_1_1,
|
|
'trace' => 1,
|
|
'style' => SOAP_RPC,
|
|
'use' => SOAP_ENCODED,
|
|
));
|
|
}
|
|
|
|
public function getZonage($adrNum, $adrIndRep, $adrTypeVoie, $adrLibVoie, $cp, $ville='', $codeRivoli='', $rnvp=false, $raisonSociale='TEST', $debug=false)
|
|
{
|
|
$tabRep = array();
|
|
if (!$rnvp) {
|
|
if ($cp < 10000) {
|
|
$cp='0'.$cp;
|
|
}
|
|
$dep2 = substr($cp,0,2)*1;
|
|
$dep3 = substr($cp,0,3)*1;
|
|
switch ($dep2) {
|
|
case 0:
|
|
case 97: // DOM
|
|
case 98: // TOM
|
|
case 99: // Etranger
|
|
return $tabRep;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
$adresse = addslashes(trim(preg_replace('/ +/',' ', "$adrNum $adrIndRep $adrTypeVoie $adrLibVoie")));
|
|
$ville = addslashes($ville);
|
|
$majForcee = false;
|
|
|
|
$ret = $this->iDb->select(
|
|
'jo.zonage', 'zus, zru, zfu, cucs, rnvpStatut, rnvpCorr, rnvpTrt, adr3, adr4, adr5, adr6, adr7, numVoieA, indRepA,
|
|
typeVoieAlong, typeVoieAcourt, corpVoie, motDir, motDirD, libVoieSec, adr4n32, adr4n38, clePostaleVoie,
|
|
secteur, cleRoutage, cpx, cleAd, codPaysIso2, codPaysIso3, libPays, codeInsee',
|
|
"address='$adresse' AND adr_cp='$cp' AND adr_ville='$ville'",false, MYSQL_ASSOC);
|
|
|
|
if (count($ret) > 0) {
|
|
$zones = $ret[0];
|
|
if ($zones['rnvpStatut'] === null && $rnvp) {
|
|
$majForcee = true;
|
|
}
|
|
$tabRep['ZUS'] = $tabRep['ZFU'] = $tabRep['ZRU'] = $tabRep['CUCS'] = 'NON';
|
|
|
|
if (trim($zones['zus']) != '') {
|
|
if (trim($zones['zus']) == 'NSP') {
|
|
$tabRep['ZUS'] = 'NSP';
|
|
}
|
|
else {
|
|
$tabRep['ZUS'] = 'OUI';
|
|
}
|
|
$tabRep['NZUS'] = $zones['zus'];
|
|
}
|
|
if (trim($zones['zru']) != '') {
|
|
if (trim($zones['zru']) == 'NSP') {
|
|
$tabRep['ZRU'] = 'NSP';
|
|
}
|
|
else {
|
|
$tabRep['ZRU'] = 'OUI';
|
|
}
|
|
$tabRep['NZRU'] = $zones['zru'];
|
|
}
|
|
if (trim($zones['zfu']) != '') {
|
|
if (trim($zones['zfu']) == 'NSP') {
|
|
$tabRep['ZFU'] = 'NSP';
|
|
}
|
|
else {
|
|
$tabRep['ZFU'] = 'OUI';
|
|
}
|
|
$tabRep['NZFU'] = $zones['zfu'];
|
|
}
|
|
if (trim($zones['cucs']) != '') {
|
|
if (trim($zones['cucs']) == 'NSP') {
|
|
$tabRep['CUCS'] = 'NSP';
|
|
}
|
|
else {
|
|
$tabRep['CUCS'] = 'OUI';
|
|
}
|
|
$tabRep['NCUCS'] = $zones['cucs'];
|
|
}
|
|
|
|
/** Autres Informations de la RNVP **/
|
|
if ($rnvp) {
|
|
if (strtoupper(@trim($zones['adr7'])) == 'FRANCE') {
|
|
$zones['adr7'] = '';
|
|
}
|
|
$tabRep['ADR3'] = @trim($zones['adr3']);
|
|
$tabRep['ADR4'] = @trim($zones['adr4']);
|
|
$tabRep['ADR5'] = @trim($zones['adr5']);
|
|
$tabRep['ADR6'] = @trim($zones['adr6']);
|
|
$tabRep['ADR7'] = trim($zones['adr7']);
|
|
}
|
|
|
|
}
|
|
|
|
if (count($ret) == 0 || $majForcee) {
|
|
try {
|
|
// Le RNVP ne fonctionne pas sans la Raison Sociale qui est la 1ère ligne d'adresse
|
|
if (trim($raisonSociale) == '') {
|
|
$raisonSociale = 'TEST';
|
|
}
|
|
$rep = $this->client->zonage(
|
|
new SoapParam(strtr(
|
|
"$raisonSociale:$adresse:$cp:$ville",
|
|
'¿°ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ??',
|
|
' aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr'),'adresse'),
|
|
new SoapParam(':','separateur'),
|
|
new SoapParam('type=M','options')
|
|
);
|
|
|
|
|
|
/** Découpage des ZFU, CUCS etcs... **/
|
|
$fp = fopen(LOG_PATH.'/amabis.log', 'a');
|
|
fwrite($fp, date('d-m-Y H:i:s').' - '.implode("\n", $rep)."\n============================================================================\n");
|
|
fclose($fp);
|
|
|
|
$tabZones = explode(',',$rep['zonage']); // ZUS=OUI,NZUS=1127020,ZFU=OUI,NZFU=11270ZF,CUCS=OUI,NCUCS=1127020
|
|
foreach ($tabZones as $zone) {
|
|
$tabTmp = explode('=',$zone);
|
|
if (trim($tabTmp[0]) != '') {
|
|
$tabRep[$tabTmp[0]]=$tabTmp[1];
|
|
}
|
|
}
|
|
if (@$tabRep['ZUS']=='NSP') $tabRep['NZUS']='NSP';
|
|
if (@$tabRep['ZRU']=='NSP') $tabRep['NZRU']='NSP';
|
|
if (@$tabRep['ZFU']=='NSP') $tabRep['NZFU']='NSP';
|
|
if (@$tabRep['CUCS']=='NSP') $tabRep['NCUCS']='NSP';
|
|
$adresse=stripslashes(trim(preg_replace('/ +/',' ', "$adrNum $adrIndRep $adrTypeVoie $adrLibVoie")));
|
|
$ville=stripslashes($ville);
|
|
$tabRepTmp=array();
|
|
$tabTmp=explode('=',utf8_decode($rep['objdesc']));
|
|
//print_r($tabTmp);
|
|
//die();
|
|
$tabZones=array();
|
|
foreach ($tabTmp as $iZone=>$zone) {
|
|
$pos=strrpos($zone,',');
|
|
if ($iZone==0) {
|
|
$nomZoneSuiv=$zone;
|
|
continue;
|
|
}
|
|
$tabZones[$nomZoneSuiv]=substr($zone,0,$pos);
|
|
$nomZoneSuiv=substr($zone,$pos+1);
|
|
}
|
|
if (strtoupper(@trim($tabZones['ADR7']))=='FRANCE') $tabZones['ADR7']='';
|
|
$tabTmp=explode('|', $tabZones['VOIEA']);
|
|
$typeVoieAcourt=@trim($tabTmp[1]);
|
|
$tabInsert=array(
|
|
'address'=>$adresse,
|
|
'adr_cp'=>$cp,
|
|
'adr_ville'=>$ville,
|
|
'zus'=>@$tabRep['NZUS'],
|
|
'zru'=>@$tabRep['NZRU'],
|
|
'zfu'=>@$tabRep['NZFU'],
|
|
'cucs'=>@$tabRep['NCUCS'],
|
|
);
|
|
$tabUpdate=array(
|
|
'adrNum'=>$adrNum,
|
|
'adrIndRep'=>$adrIndRep,
|
|
'adrTypeVoie'=>$adrTypeVoie,
|
|
'adrLibVoie'=>$adrLibVoie,
|
|
'rivoli'=>$codeRivoli,
|
|
// Ajouté le 16/12/2013
|
|
'rnvpStatut' => substr($tabZones['STATUTC'],0,2),
|
|
'rnvpCorr' => substr($tabZones['STATUTC'],2,1),
|
|
'rnvpTrt' => trim(substr($tabZones['STATUTC'],3,2)),
|
|
'adr3' => @trim($tabZones['ADR3']),
|
|
'adr4' => @trim($tabZones['ADR4']),
|
|
'adr5' => @trim($tabZones['ADR5']),
|
|
'adr6' => @trim($tabZones['ADR6']),
|
|
'adr7' => trim($tabZones['ADR7']),
|
|
'numVoieA' => @trim($tabZones['NUM1']),
|
|
'indRepA' => @trim($tabZones['BTQC1']),
|
|
'typeVoieAlong' => @trim($tabZones['TYPVOIEL']),
|
|
'typeVoieAcourt' => $typeVoieAcourt,
|
|
'corpVoie' => @trim($tabZones['CORPSVOIE']),
|
|
'motDir' => @trim($tabZones['MOTDIR']),
|
|
'motDirD' => @trim($tabZones['MOTDIRD']),
|
|
'libVoieSec' => @trim($tabZones['VOIREFLIBS']),
|
|
'adr4n32' => @trim($tabZones['VOIREFLIBPOS']),
|
|
'adr4n38' => @trim($tabZones['VOIREFLIBPOS2']),
|
|
'clePostaleVoie' => @trim($tabZones['VOIREFCLEPOST']),
|
|
'secteur' => @trim($tabZones['SECTEUR']),
|
|
'cleRoutage' => @trim($tabZones['CLER']),
|
|
'cpx' => @trim($tabZones['CPX']),
|
|
'cleAd' => @trim($tabZones['CLEAD']),
|
|
'codPaysIso2' => @trim($tabZones['NATREFISO2']),
|
|
'codPaysIso3' => @trim($tabZones['NATREFISO3']),
|
|
'libPays' => @trim($tabZones['NATREFLIB']),
|
|
'codeInsee' => @trim($tabZones['LOCREFCLEO']),
|
|
'source' => 'Amabis',
|
|
);
|
|
$dateInsert=0;
|
|
if ($majForcee) {
|
|
$adresseL=addslashes($adresse);
|
|
$villeL=addslashes($ville);
|
|
|
|
$ret = $this->iDb->select('jo.zonage', 'dateInsert*1 as dateInsert', "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false);
|
|
$dateInsert=@$ret[0]['dateInsert']*1;
|
|
$this->iDb->update('jo.zonage', array_merge($tabUpdate,array('dateInsert'=>$dateInsert)), "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false);
|
|
//echo "Mise à jour de l'adresse du $dateInsert pour address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'".PHP_EOL;
|
|
}
|
|
|
|
if ($dateInsert==0) {
|
|
$this->iDb->insert('jo.zonage', array_merge($tabInsert,$tabUpdate), false);
|
|
//echo "Insertion de l'adresse (".$zones['rnvpStatut'].")!".PHP_EOL;
|
|
}
|
|
|
|
$tabTmp[0]=explode(',', $tabZones['LOCREFCLEP']);
|
|
$tabTmp[1]=explode(',', $tabZones['LOCREFCP']);
|
|
$tabTmp[2]=explode(',', $tabZones['LOCREFTYPP']);
|
|
$tabTmp[3]=explode(',', $tabZones['LOCREFLIBD']);
|
|
$tabTmp[4]=explode(',', $tabZones['LOCREFLIBD2']);
|
|
foreach($tabTmp[0] as $iCleP=>$cleP) {
|
|
$tabInsert = array(
|
|
'codeInsee' => @trim($tabZones['LOCREFCLEO']),
|
|
'villeLib' => @trim($tabZones['LOCREFLIBP']),
|
|
'villePopu' => @trim($tabZones['LOCREFPOP']),
|
|
'cleAchPost'=> $cleP,
|
|
'codePostal'=> $tabTmp[1][$iCleP],
|
|
'typePostal'=> $tabTmp[2][$iCleP],
|
|
'libAchP32' => @preg_replace('/^\//','',$tabTmp[3][$iCleP]),
|
|
'libAchP38' => @preg_replace('/^\//','',$tabTmp[4][$iCleP]),
|
|
'source' => 'Amabis',
|
|
'dateInsert'=> date('YmdHis'),
|
|
);
|
|
$this->iDb->insert('jo.villesCP', $tabInsert, false);
|
|
}
|
|
|
|
/** Autres Informations de la RNVP **/
|
|
if ($rnvp) {
|
|
$tabRep['ADR3'] = @trim($tabZones['ADR3']);
|
|
$tabRep['ADR4'] = @trim($tabZones['ADR4']);
|
|
$tabRep['ADR5'] = @trim($tabZones['ADR5']);
|
|
$tabRep['ADR6'] = @trim($tabZones['ADR6']);
|
|
$tabRep['ADR7'] = trim($tabZones['ADR7']);
|
|
}
|
|
} catch (SoapFault $fault) {
|
|
$fp = fopen(LOG_PATH.'/amabis.log', 'a');
|
|
fwrite($fp, date('d-m-Y H:i:s').' - ERREUR SOAP : Requete = '.$this->client->__getLastRequest()."\n Reponse = ".$this->client->__getLastResponse()."\n============================================================================\n");
|
|
fclose($fp);
|
|
}
|
|
//return $tabRep;
|
|
}
|
|
|
|
/** Zonages AFR et ZRR
|
|
**/
|
|
$codeInsee=substr($codeRivoli,0,5);
|
|
$ret = $this->iDb->select('jo.zonageInsee', 'typeZone, arreteDate, decretDate, decretNum, decretModifieDate, decretModifieNum, dateDebut, dateFin', "codeInsee='$codeInsee'",false, MYSQL_ASSOC);
|
|
$tabRep['ZRR']=$tabRep['AFR']='NON';
|
|
foreach ($ret as $zones)
|
|
switch ($zones['typeZone']) {
|
|
case 'ZRR': $tabRep['ZRR']='OUI'; $tabRep['NZRR']=$codeInsee; break;
|
|
case 'ZAFR': $tabRep['AFR']='OUI'; $tabRep['NAFR']=$codeInsee; break;
|
|
default: break;
|
|
}
|
|
|
|
return $tabRep;
|
|
}
|
|
|
|
public function searchByTelFax($tel)
|
|
{
|
|
return $this->getTelFax('','','','',$tel);
|
|
}
|
|
|
|
public function getTelFax($nom, $cp, $ville='', $prenom='', $tel='')
|
|
{
|
|
if (trim($tel) != '') {
|
|
$query = "<telep>$tel</telep><scoremini>10</scoremini><distinction>30</distinction>";
|
|
}
|
|
elseif (trim($prenom) == '') {
|
|
$query = "<rs>$nom</rs><cpville>$cp $ville</cpville><scoremini>90</scoremini><distinction>30</distinction>";
|
|
}
|
|
else {
|
|
$query = "<nom>$nom</nom><prenom>$prenom</prenom><cpville>$cp $ville</cpville><scoremini>90</scoremini><distinction>30</distinction>";
|
|
}
|
|
|
|
$rep = $this->client->rechtel($query);
|
|
|
|
$fp = fopen(LOG_PATH.'/amabis.log', 'a');
|
|
fwrite($fp, date('d-m-Y H:i:s')." - $query - ".implode("\n", $rep)."\n============================================================================\n");
|
|
fwrite($fp, "Requête : ".$this->client->__getLastRequest()."\n");
|
|
fwrite($fp, "Réponse : ".$this->client->__getLastResponse()."\n");
|
|
fclose($fp);
|
|
}
|
|
}
|