MAmabis : doctrine
This commit is contained in:
parent
4af63ee34a
commit
2c8eaf28ef
@ -5,23 +5,24 @@ ini_set('default_socket_timeout', 30);
|
||||
class Metier_Partenaires_MAmabis
|
||||
{
|
||||
protected $client;
|
||||
protected $iDb;
|
||||
|
||||
public function __construct($db = null)
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if ($db === null) {
|
||||
$this->iDb = new Metier_Util_Db();
|
||||
} else {
|
||||
$this->iDb = $db;
|
||||
}
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
|
||||
$this->client = new SoapClient(null, array(
|
||||
'location' => 'http://sw2.amabis.com:5100/',
|
||||
'uri' => 'http://www.amabis.com/ns.xsd',
|
||||
'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,
|
||||
'soap_version' => SOAP_1_1,
|
||||
'trace' => 1,
|
||||
'style' => SOAP_RPC,
|
||||
'use' => SOAP_ENCODED,
|
||||
));
|
||||
}
|
||||
@ -51,14 +52,16 @@ class Metier_Partenaires_MAmabis
|
||||
$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);
|
||||
$sql = "SELECT 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
|
||||
FROM jo.zonage WHERE address='$adresse' AND adr_cp='$cp' AND adr_ville='$ville'";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if (count($ret) > 0) {
|
||||
$zones = $ret[0];
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$zones = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
if ($zones['rnvpStatut'] === null && $rnvp) {
|
||||
$majForcee = true;
|
||||
}
|
||||
@ -110,7 +113,7 @@ class Metier_Partenaires_MAmabis
|
||||
}
|
||||
}
|
||||
|
||||
if (count($ret) == 0 || $majForcee) {
|
||||
if ($stmt->rowCount() == 0 || $majForcee) {
|
||||
try {
|
||||
// Le RNVP ne fonctionne pas sans la Raison Sociale qui est la 1ère ligne d'adresse
|
||||
if (trim($raisonSociale) == '') {
|
||||
@ -169,88 +172,99 @@ class Metier_Partenaires_MAmabis
|
||||
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'],
|
||||
$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,
|
||||
'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']),
|
||||
'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']),
|
||||
'corpVoie' => @trim($tabZones['CORPSVOIE']),
|
||||
'motDir' => @trim($tabZones['MOTDIR']),
|
||||
'motDirD' => @trim($tabZones['MOTDIRD']),
|
||||
'motDirD' => @trim($tabZones['MOTDIRD']),
|
||||
'libVoieSec' => @trim($tabZones['VOIREFLIBS']),
|
||||
'adr4n32' => @trim($tabZones['VOIREFLIBPOS']),
|
||||
'adr4n38' => @trim($tabZones['VOIREFLIBPOS2']),
|
||||
'adr4n32' => @trim($tabZones['VOIREFLIBPOS']),
|
||||
'adr4n38' => @trim($tabZones['VOIREFLIBPOS2']),
|
||||
'clePostaleVoie' => @trim($tabZones['VOIREFCLEPOST']),
|
||||
'secteur' => @trim($tabZones['SECTEUR']),
|
||||
'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']),
|
||||
'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;
|
||||
$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;
|
||||
$adresseL = addslashes($adresse);
|
||||
$villeL = addslashes($ville);
|
||||
$sql = "SELECT dateInsert*1 as dateInsert FROM jo.zonage
|
||||
WHERE address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$dateInsert = $result->dateInsert;
|
||||
if ($dateInsert != 0) {
|
||||
$this->conn->update('jo.zonage', array_merge($tabUpdate,
|
||||
array('dateInsert' => $dateInsert)),
|
||||
array(
|
||||
'address' => $adresseL,
|
||||
'adr_cp' => $cp,
|
||||
'adr_ville' => $villeL,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($dateInsert==0) {
|
||||
$this->iDb->insert('jo.zonage', array_merge($tabInsert, $tabUpdate), false);
|
||||
//echo "Insertion de l'adresse (".$zones['rnvpStatut'].")!".PHP_EOL;
|
||||
if ($dateInsert == 0) {
|
||||
$this->conn->insert('jo.zonage', array_merge($tabInsert, $tabUpdate));
|
||||
}
|
||||
|
||||
$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']);
|
||||
$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'),
|
||||
'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);
|
||||
$this->conn->insert('jo.villesCP', $tabInsert);
|
||||
}
|
||||
|
||||
/** Autres Informations de la RNVP **/
|
||||
@ -266,19 +280,30 @@ class Metier_Partenaires_MAmabis
|
||||
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;
|
||||
/** Zonages AFR et ZRR **/
|
||||
$codeInsee = substr($codeRivoli, 0, 5);
|
||||
$sql = "SELECT typeZone, arreteDate, decretDate, decretNum, decretModifieDate, decretModifieNum, dateDebut, dateFin
|
||||
FROM jo.zonageInsee WHERE codeInsee=:code";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('code', $codeInsee);
|
||||
$stmt->execute();
|
||||
$tabRep['ZRR'] = $tabRep['AFR'] = 'NON';
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($zones = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
switch ($zones['typeZone']) {
|
||||
case 'ZRR':
|
||||
$tabRep['ZRR'] = 'OUI';
|
||||
$tabRep['NZRR'] = $codeInsee;
|
||||
break;
|
||||
case 'ZAFR':
|
||||
$tabRep['AFR']='OUI';
|
||||
$tabRep['NAFR']=$codeInsee;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user