2016-03-15 12:59:58 +00:00

144 lines
4.5 KiB
PHP

<?php
class SdMetier_Rnvp_Adresse
{
protected $source;
protected $sourceId;
protected $columns = array(
'L1rnvp',
'L2rnvp',
'L3rnvp',
'L4rnvp',
'L5rnvp',
'L6rnvp',
'L7rnvp',
'dateRetourRnvp',
'codeRetour',
'LPAD(Insee,5,0) as Insee',
'CorrectionImportante',
'CorrectionDouteuse',
'CQadrs',
'HexaCle',
'NumDept',
'IdHexavia',
'IdHexaposte',
'Iris_Rivoli',
'Iris_Ilot99',
'Iris_CodeIris',
'Iris_Canton',
'Cdx_Matricule',
'Cdx_V5Geo',
'Cdx_V6Geo',
'Cdx_V5Cdx',
'Cdx_V6Cdx',
'dateInsert',
'dateUpdate',
);
/**
* Récupération de l'adresse normalisé
*/
public function __construct(){}
/**
*
* @param unknown $companyId
*/
public function setCompanyId($companyId)
{
$this->source = substr($companyId,0,3);
$this->sourceId = substr($companyId,3,20);
}
/**
* Id de l'entreprise à partir du siret
* @param string $companyId
* @throws Exception
* @return NULL
*/
public function setCompanyIdProxy($companyId)
{
try {
$etabM = new Application_Model_JoEtablissements();
$sql = $etabM->select(true)->columns(array('LPAD(source,3,0)', 'LPAD(source_id,20,0)'))
->where('siren=?', substr($companyId,0,9))
->where('nic=?', substr($companyId,9,5));
$etabResult = $etabM->fetchRow($sql);
if ($etabResult === null) {
return null;
}
$this->source = $etabResult->source;
$this->sourceId = $etabResult->source_id;
} catch (Zend_Db_Exception $e) {
throw new Exception($e->getMessage(), 'ERR');
}
}
/**
* Formattage de l'adresse normalisé
* @return stdClass
* @throws Exception
*/
public function format()
{
try
{
$rnvpM = new Application_Model_VillesRnvpSources();
$sql = $rnvpM->select(true)->columns($this->columns)
->where('source=?', $this->source)
->where('source_id=?', $this->sourceId);
$rnvpResult = $rnvpM->fetchRow($sql);
if ($rnvpResult === null) {
return null;
}
$rnvp = new stdClass();
$rnvp->L1 = $rnvpResult->L1rnvp;
$rnvp->L2 = $rnvpResult->L2rnvp;
$rnvp->L3 = $rnvpResult->L3rnvp;
$rnvp->L4 = $rnvpResult->L4rnvp;
$rnvp->L5 = $rnvpResult->L5rnvp;
$rnvp->L6 = $rnvpResult->L6rnvp;
$rnvp->L7 = $rnvpResult->L7rnvp;
$rnvp->ProcessCode = $rnvpResult->codeRetour;
$process = new SdMetier_Rnvp_Process();
$correction = '';
if ($rnvpResult->CorrectionImportante == 'I') {
$correction = $rnvpResult->CorrectionImportante;
}
if ($rnvpResult->CorrectionDouteuse == 'D') {
$correction = $rnvpResult->CorrectionDouteuse;
}
$rnvp->ProcessLabel = $process->getLabel($rnvpResult->codeRetour, $correction);
$rnvp->ProcessDate = $rnvpResult->dateRetourRnvp;
// Label CQadrs
$rnvp->QualityCode = $rnvpResult->CQadrs;
$quality = new SdMetier_Rnvp_Quality();
$rnvp->QualityLabel = $quality->getLabel($rnvp->QualityCode);
$rnvp->GeoInseeCommune = $rnvpResult->Insee;
$rnvp->GeoHexavia = $rnvpResult->IdHexavia;
$rnvp->GeoHexapost = $rnvpResult->IdHexaposte;
$rnvp->GeoHexacle = $rnvpResult->HexaCle;
$rnvp->GeoDepartement = $rnvpResult->NumDept;
$rnvp->GeoRivoliCode = $rnvpResult->Iris_Rivoli;
$rnvp->GeoIlot = $rnvpResult->Iris_Ilot99;
$rnvp->GeoIris = $rnvpResult->Iris_CodeIris;
$rnvp->GeoCanton = $rnvpResult->Iris_Canton;
$rnvp->CedexaMatricule = $rnvpResult->Cdx_Matricule;
$rnvp->CedexaGeoL5 = $rnvpResult->Cdx_V5Geo;
$rnvp->CedexaGeoL6 = $rnvpResult->Cdx_V6Geo;
$rnvp->CedexaCdxL5 = $rnvpResult->Cdx_V5Cdx;
$rnvp->CedexaCdxL6 = $rnvpResult->Cdx_V6Cdx;
$rnvp->DateInsert = $rnvpResult->dateInsert;
$rnvp->DateUpdate = $rnvpResult->dateUpdate;
} catch (Zend_Db_Exception $e) {
throw new Exception($e->getMessage(), 'ERR');
}
return $rnvp;
}
}