Doctrine et empreinte
This commit is contained in:
parent
ea16090016
commit
3db44ee7fe
@ -2040,7 +2040,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
|
||||
$tdeb = microtime(1);
|
||||
}
|
||||
|
||||
$iTva = new Metier_Partenaires_MTva($this->iDb);
|
||||
$iTva = new Metier_Partenaires_MTva();
|
||||
$iTva->setCompanyId($siren);
|
||||
$iTva->setRemote();
|
||||
$iTva->getTVA();
|
||||
|
@ -21,7 +21,11 @@ class Metier_Partenaires_MTva
|
||||
*/
|
||||
protected $cle;
|
||||
|
||||
protected $iDb;
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* Remote Flag
|
||||
@ -30,17 +34,12 @@ class Metier_Partenaires_MTva
|
||||
protected $remote = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown $db
|
||||
* TVA
|
||||
* @return boolean
|
||||
*/
|
||||
public function __construct($db = null)
|
||||
public function __construct()
|
||||
{
|
||||
if ($db === null) {
|
||||
$this->iDb = new Metier_Util_Db();
|
||||
} else {
|
||||
$this->iDb = $db;
|
||||
}
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,12 +56,6 @@ class Metier_Partenaires_MTva
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($db === null) {
|
||||
$this->iDb = new Metier_Util_Db();
|
||||
} else {
|
||||
$this->iDb = $db;
|
||||
}
|
||||
|
||||
$cleAlgo = $this->genereCleFr();
|
||||
if ($cleAlgo < 10) {
|
||||
$this->cle = '0'.$cleAlgo;
|
||||
@ -77,11 +70,16 @@ class Metier_Partenaires_MTva
|
||||
return false;
|
||||
}
|
||||
|
||||
$info = $this->iDb->select('sdv1.siren_tva',
|
||||
"LPAD(cle,2,0) AS cle, DATE_FORMAT(dateMod,'%Y%m%d') as DateMAJ",
|
||||
"siren=".$this->siren, false, MYSQL_ASSOC);
|
||||
if (count($info) > 0) {
|
||||
$tab = $info[0];
|
||||
$exist = false;
|
||||
|
||||
$sql = "SELECT LPAD(cle,2,0) AS cle, DATE_FORMAT(dateMod,'%Y%m%d') as DateMAJ
|
||||
FROM sdv1.siren_tva WHERE siren=:siren";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('siren', $siren);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$exist = true;
|
||||
$tab = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$cle = $tab['cle'];
|
||||
$dateRef = new DateTime();
|
||||
$dateRef->sub(new DateInterval('P6M'));
|
||||
@ -97,7 +95,7 @@ class Metier_Partenaires_MTva
|
||||
}
|
||||
|
||||
if ($this->remote) {
|
||||
return $this->getRemoteVAT();
|
||||
return $this->getRemoteVAT($exist);
|
||||
} else {
|
||||
$this->vatNumber = "FR".$this->cle.$this->siren;
|
||||
$this->vatDefined = false;
|
||||
@ -130,9 +128,10 @@ class Metier_Partenaires_MTva
|
||||
|
||||
/**
|
||||
* Get Data form website
|
||||
* @param boolean $exist
|
||||
* @return boolean
|
||||
*/
|
||||
protected function getRemoteVAT()
|
||||
protected function getRemoteVAT($exist)
|
||||
{
|
||||
$url = 'http://ec.europa.eu/taxation_customs/vies/vatResponse.html';
|
||||
|
||||
@ -160,21 +159,13 @@ class Metier_Partenaires_MTva
|
||||
$body = $response->getBody();
|
||||
if (preg_match('/Yes, valid VAT number/i', $body)
|
||||
|| preg_match('/Oui, numéro de TVA valide/i', $body)) {
|
||||
$tabInsert = array(
|
||||
'siren' => $this->siren,
|
||||
'cle' => $this->cle,
|
||||
'duree' => $time
|
||||
);
|
||||
if (!$this->iDb->insert('sdv1.siren_tva', $tabInsert)) {
|
||||
$tabUpdate = array(
|
||||
'cle' => $this->cle,
|
||||
'duree' => $time
|
||||
);
|
||||
if (!$this->iDb->update('sdv1.siren_tva', $tabUpdate, "siren=$this->siren")) {
|
||||
Metier_Util_Log::write('W', "Siren $this->siren, numéro de TVA = FR $this->cle $this->siren, impossible de MAJ la clef ($time s) - ERREUR MySql n°". mysql_errno() .' : '. mysql_error(), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||||
}
|
||||
if ($exist) {
|
||||
$this->conn->update('sdv1.siren_tva', array('cle' => $this->cle,
|
||||
'duree' => $time), array('siren' => $this->siren));
|
||||
} else {
|
||||
$this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren,
|
||||
'cle' => $this->cle, 'duree' => $time));
|
||||
}
|
||||
Metier_Util_Log::write('I', "Siren $this->siren, numéro de TVA = FR $this->cle $siren ($time s)", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||||
$this->vatNumber = "FR".$this->cle.$this->siren;
|
||||
$this->vatDefined = true;
|
||||
return true;
|
||||
@ -184,21 +175,15 @@ class Metier_Partenaires_MTva
|
||||
Metier_Util_Log::write('I', "TVA ".$e->getMessage(), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||||
}
|
||||
|
||||
$tabInsert = array(
|
||||
'siren' => $this->siren,
|
||||
'cle' => 'NULL',
|
||||
'duree' => $time
|
||||
);
|
||||
$tabUpdate = array(
|
||||
'cle' => 'NULL',
|
||||
'duree' => $time
|
||||
);
|
||||
if (!$this->iDb->insert('sdv1.siren_tva', $tabInsert)) {
|
||||
if (!$this->iDb->update('sdv1.siren_tva', $tabUpdate, "siren=$this->siren")) {
|
||||
Metier_Util_Log::write('W', "Siren $this->siren, numéro de TVA = FR $this->cle $this->siren, impossible de MAJ la clef ($time s) - ERREUR MySql n°". mysql_errno() .' : '. mysql_error(), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||||
}
|
||||
// Non disponible
|
||||
if ($exist) {
|
||||
$this->conn->update('sdv1.siren_tva', array('cle' => 'NULL', 'duree' => $time),
|
||||
array('siren' => $this->siren));
|
||||
} else {
|
||||
$this->conn->insert('sdv1.siren_tva', array('siren' => $this->siren,
|
||||
'cle' => 'NULL', 'duree' => $time));
|
||||
}
|
||||
Metier_Util_Log::write('I', "Siren $this->siren, numéro de TVA = FR $this->cle $this->siren vérification non disponible ($time s)", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
|
||||
|
||||
$this->vatNumber = "FR".$this->cle.$this->siren;
|
||||
$this->vatDefined = false;
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user