batch/includes/partenaires/classMAmabis.php
2015-07-20 08:17:28 +00:00

324 lines
13 KiB
PHP
Raw Permalink Blame History

<?php
ini_set('soap.wsdl_cache_enabled', 0);
class AmaSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version) {
/* $request = strtr($request, array('<ns1:'=>'<ama:',
'</ns1:'=>'</ama:',
// '<param0 xsi:type="xsd:string">'=>'',
'xmlns:ns1="http://www.amabis.com/ama.xsd"'=>'xmlns:ama="http://www.amabis.com/ama.xsd"',
// '</param0>'=>'',
// '&lt;'=>'<',
// '&gt;'=>'>',
)
);*/
return parent::__doRequest($request, $location, $action, $version);
}
}
class MAmabis {
private $client;
function __construct() {
/* $this->client = new AmaSoapClient(null, //'http://www.amabis.com/ama.wsdl',//null, //
array( 'location' => AMABIS_WS_URL,//'http://sw4.amabis.com:5101',
'uri' => AMABIS_WS_URI,//'http://sw4.amabis.com:5101',
'soap_version' => SOAP_1_1,
'trace' => 1,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'connection_timeout'=> 2,
)
);
*/
$this->client = new AmaSoapClient(null,
array( //'location' => 'http://sw4.amabis.com:5100',
'location' => 'http://sw2.amabis.com:5100/',
'uri' => 'http://www.amabis.com/ns.xsd',
'connection_timeout' => 2,
'default_socket_timeout'=> 2,
'soap_version' => SOAP_1_1,
'trace' => 1,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
)
);
}
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 5:
case 9:
case 15:
case 19:
case 23:
case 32:
case 46:
case 48:
case 82:*/
case 97: // DOM
case 98: // TOM
case 99: // Etranger
return $tabRep;
break;
default:
//if ($dep3==975) return $tabRep;
break;
}
}
$iDb=new WDB();
$adresse=addslashes(trim(preg_replace('/ +/',' ', "$adrNum $adrIndRep $adrTypeVoie $adrLibVoie")));
$ville=addslashes($ville);
$majForcee=false;
$ret=$iDb->select( '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);
$zones=@$ret[0];
if (count($ret)>0) {
if ($zones['rnvpStatut']===null && $rnvp) $majForcee=true;
$tabRep['ZUS'] =$tabRep['ZFU'] =$tabRep['ZRU'] =$tabRep['CUCS'] ='NON';
//$tabRep['NZUS']=$tabRep['NZFU']=$tabRep['NZRU']=$tabRep['NCUCS']='';
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) {
//$tabRep['ADR1']=@trim($tabZones['ADR1']);
//$tabRep['ADR2']=@trim($tabZones['ADR2']);
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 {
if (trim($raisonSociale)=='') $raisonSociale='TEST'; // Le RNVP ne fonctionne pas sans la Raison Sociale qui est la 1<>re ligne d'adresse
$rep=$this->client->zonage( new SoapParam(strtr("$raisonSociale:$adresse:$cp:$ville",
'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>??',
' aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr'),'adresse'),
new SoapParam(':','separateur'),
new SoapParam('type=M','options')
);
/*$rep=$this->client->zonage( "<adresse></adresse>".
"<separateur>:</separateur>".
"<options>type=M</options>");*/
/** D<>coupage des ZFU, CUCS etcs...
**/
$fp=fopen('/var/www/log/amabis.log', 'a');
fwrite($fp, date('d-m-Y H:i:s').' - '.implode("\n", $rep)."\n============================================================================\n");
fclose($fp);
//print_r($rep);
//die();
$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<75> 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=$iDb->select('zonage', 'dateInsert*1 as dateInsert', "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false);
$dateInsert=@$ret[0]['dateInsert']*1;
$iDb->update('zonage', array_merge($tabUpdate,array('dateInsert'=>$dateInsert)), "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false);
echo "Mise <20> jour de l'adresse du $dateInsert pour address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'".EOL;
}
if ($dateInsert==0) {
$iDb->insert('zonage', array_merge($tabInsert,$tabUpdate), false);
//echo "Insertion de l'adresse (".$zones['rnvpStatut'].")!".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'),
);
$iDb->insert('villesCP', $tabInsert, false);
//echo mysql_error().EOL;
}
/** Autres Informations de la RNVP
**/
if ($rnvp) {
//$tabRep['ADR1']=@trim($tabZones['ADR1']);
//$tabRep['ADR2']=@trim($tabZones['ADR2']);
$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) {
echo 'ERREUR SOAP :'.EOL;
print_r($fault);
echo $this->client->__getLastRequest()."\n";
echo $this->client->__getLastResponse()."\n";
$fp=fopen('/var/www/log/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=$iDb->select( '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;
}
function searchByTelFax($tel) {
return $this->getTelFax('','','','',$tel);
}
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('/var/www/log/amabis.log', 'a');
fwrite($fp, date('d-m-Y H:i:s')." - $query - ".implode("\n", $rep)."\n============================================================================\n");
fwrite($fp, "Requ<EFBFBD>te : ".$this->client->__getLastRequest()."\n");
fwrite($fp, "R<EFBFBD>ponse : ".$this->client->__getLastResponse()."\n");
fclose($fp);
}
}
?>