Library Update

This commit is contained in:
Michael RICOIS 2017-01-05 15:24:51 +01:00
parent 6f5226b351
commit d7cf89e49d
3 changed files with 192 additions and 170 deletions

View File

@ -987,7 +987,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
e.adr_comp, LPAD(e.adr_cp,5,0) AS adr_cp, e.adr_ville, e.adr_dep, LPAD(e.adr_com,3,0) AS adr_com,
LPAD(e.tel,10,0) AS tel, LPAD(e.fax,10,0) AS fax, e.cj, e.ape_etab, e.ape_entrep, e.teff_etab,
CONCAT(e.siren, e.nic) AS siret, e.actif, e.identite_pre, IF(e.siege=2,0.5,e.siege) AS triSiege,
IF (e.adr_dep=99, (SELECT libPays FROM jo.tabPays p WHERE p.codePaysInsee=e.adr_com) , 'France') AS libPays";
IF (e.adr_dep=99, (SELECT libPays FROM jo.tabPays p WHERE p.codePaysInsee=e.adr_com LIMIT 0,1) , 'France') AS libPays";
$strActif = $strDep = '';
if (intval($actif) == 1) {
@ -1701,7 +1701,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
$identite = $result;
}
}
if (count($identite)>0) {
if (count($identite) > 0) {
// --- Actif
$identite['Actif'] = 1;
if (array_key_exists('insEVE', $identite)) {
@ -1743,11 +1743,11 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
}
rsort($tabDates);
$dateProcol = str_replace('-', '', $tabDates[0])*1;
if ($this->dureePlan>0 && date('Ymd')<$this->finPlan) {
if ($this->dureePlan > 0 && date('Ymd') < $this->finPlan) {
$identite['SituationJuridique'] = 'PL';
}
// Plan révolu
elseif ($this->dureePlan>0 && date('Ymd')>=$this->finPlan) {
elseif ($this->dureePlan > 0 && date('Ymd') >= $this->finPlan) {
$identite['SituationJuridique'] = '';
}
// Appel de jugement
@ -1758,9 +1758,13 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
else {
$identite['SituationJuridique'] = 'P';
}
} elseif (count($this->getAnnoncesLegales($siren, 0, 'A', false)) > 0) {
}
// Absorption
elseif (count($this->getAnnoncesLegales($siren, 0, 'A', false)) > 0) {
$identite['SituationJuridique'] = 'A';
} elseif (count($this->getAnnoncesLegales($siren, 0, 'D', false)) > 0) {
}
// Dissolution
elseif (count($this->getAnnoncesLegales($siren, 0, 'D', false)) > 0) {
$identite['SituationJuridique'] = 'D';
}
// Fin Situation Juridique
@ -2568,91 +2572,123 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
if ($this->debug) {
file_put_contents('procol.log', "=== Situation Juridique ===\n");
}
$tabProcol = $this->getAnnoncesLegales($siren, 0, 'P', false);
if (count($tabProcol) > 0) {
$tabAnn = $this->getAnnoncesLegales($siren, 0, '', false, false);
if (count($tabAnn) > 0) {
// Date de dernière mise à jour
$tabDates = array();
foreach ($tabProcol as $iProcol => $procol) {
$tabDates[] = $procol['dateJugement'];
foreach ($tabAnn as $iAnn => $ann) {
$tabDates[] = $ann['dateInsertionSD'];
}
rsort($tabDates);
$dateProcol = str_replace('-', '', $tabDates[0])*1;
// Plan
if ($this->dureePlan > 0 && date('Ymd') < $this->finPlan) {
if ($this->debug) {
file_put_contents('procol.log', "Plan (PL) : ".$this->dureePlan."-".$this->finPlan."\n", FILE_APPEND);
}
$tabRet['SituationJuridique'] = 'PL';
}
// Plan révolu
elseif ($this->dureePlan > 0 && date('Ymd') >= $this->finPlan) {
if ($this->debug) {
file_put_contents('procol.log', "Plan revolu : ".$this->dureePlan."-".$this->finPlan."\n", FILE_APPEND);
}
$tabRet['SituationJuridique'] = '';
}
// Appel de jugement
elseif ($this->appelJugement) {
$tabRet['SituationJuridique'] = 'PA';
}
// Jugement de cloture après LJ
elseif ($this->SituationCloture) {
if ($this->debug) {
file_put_contents('procol.log', "Cloture (CL) "."\n", FILE_APPEND);
}
$tabRet['SituationJuridique'] = 'CL';
}
// En cours de procédure
else {
if ($this->debug) {
file_put_contents('procol.log', "Procol (P) "."\n", FILE_APPEND);
}
$tabRet['SituationJuridique'] = 'P';
$tabRet['dateMajANN'] = Metier_Util_Date::dateT('Y-m-d', 'Y-m-d', $tabDates[0]);
if ($tabRet['dateMajANN'] == '--') {
$tabRet['dateMajANN'] = '';
} else {
$dateAnnLastCompare = DateTime::createFromFormat('Y-m-d', $tabRet['dateMajANN']);
}
// RAZ SituationJuridique si cutoff plus récent que dernière procol
$stmt = $this->conn->executeQuery("SELECT encours, scoreSolv, scoreDir, scoreConf, DATE(dateInsert)*1 AS dateInsert, DATE(dateUpdate)*1 AS dateUpdate FROM jo.scores_cutoff WHERE siren=$siren");
if ($stmt->rowCount() > 0) {
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($result['scoreSolv'] > 0) {
//Tri des dates de procol
$tabDates = array();
foreach ($tabProcol as $iProcol=>$procol) {
$tabDates[] = $procol['dateJugement'];
// Procol
$tabProcol = $this->getAnnoncesLegales($siren, 0, 'P', false);
if (count($tabProcol) > 0) {
$tabDates = array();
foreach ($tabProcol as $iProcol => $procol) {
$tabDates[] = $procol['dateJugement'];
}
rsort($tabDates);
$dateProcol = str_replace('-', '', $tabDates[0])*1;
// Plan
if ($this->dureePlan > 0 && date('Ymd') < $this->finPlan) {
if ($this->debug) {
file_put_contents('procol.log', "Plan (PL) : ".$this->dureePlan."-".$this->finPlan."\n", FILE_APPEND);
}
rsort($tabDates);
$dateProcol = str_replace('-', '', $tabDates[0])*1;
if ($result['dateUpdate'] > $result['dateInsert']) {
$dateMaj = str_replace('-', '', $result['dateUpdate']);
} else {
$dateMaj = str_replace('-', '', $result['dateInsert']);
$tabRet['SituationJuridique'] = 'PL';
}
// Plan révolu
elseif ($this->dureePlan > 0 && date('Ymd') >= $this->finPlan) {
if ($this->debug) {
file_put_contents('procol.log', "Plan revolu : ".$this->dureePlan."-".$this->finPlan."\n", FILE_APPEND);
}
if ($dateProcol <= $dateMaj) {
$tabRet['SituationJuridique'] = '';
$tabRet['SituationJuridique'] = '';
}
// Appel de jugement
elseif ($this->appelJugement) {
$tabRet['SituationJuridique'] = 'PA';
}
// Jugement de cloture après LJ
elseif ($this->SituationCloture) {
if ($this->debug) {
file_put_contents('procol.log', "Cloture (CL) "."\n", FILE_APPEND);
}
$tabRet['SituationJuridique'] = 'CL';
}
// En cours de procédure
else {
if ($this->debug) {
file_put_contents('procol.log', "Procol (P) "."\n", FILE_APPEND);
}
$tabRet['SituationJuridique'] = 'P';
}
// RAZ SituationJuridique si cutoff plus récent que dernière procol
$stmt = $this->conn->executeQuery("SELECT encours, scoreSolv, scoreDir, scoreConf, DATE(dateInsert)*1 AS dateInsert, DATE(dateUpdate)*1 AS dateUpdate FROM jo.scores_cutoff WHERE siren=$siren");
if ($stmt->rowCount() > 0) {
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($result['scoreSolv'] > 0) {
//Tri des dates de procol
$tabDates = array();
foreach ($tabProcol as $iProcol => $procol) {
$tabDates[] = $procol['dateJugement'];
}
rsort($tabDates);
$dateProcol = str_replace('-', '', $tabDates[0])*1;
if ($result['dateUpdate'] > $result['dateInsert']) {
$dateMaj = str_replace('-', '', $result['dateUpdate']);
} else {
$dateMaj = str_replace('-', '', $result['dateInsert']);
}
if ($dateProcol <= $dateMaj) {
$tabRet['SituationJuridique'] = '';
}
}
}
}
// Absorption
if ($identite['SituationJuridique'] == '') {
$tabAnn = $this->getAnnoncesLegales($siren, 0, 'A', false);
$nbAnn = count($tabAnn);
if (count($tabAnn) > 0) {
$dateAnn = $tabAnn[$nbAnn-1]['dateInsertionSD'];
$dateAnnCompare = DateTime::createFromFormat('Y-m-d H:i:s', $dateAnn);
$dateAnnCompare->add(new DateInterval('P364D'));
if ($dateAnnCompare >= $dateAnnLastCompare) {
$tabRet['SituationJuridique'] = 'A';
}
}
}
// Dissolution
if ($identite['SituationJuridique'] == '') {
$tabAnn = $this->getAnnoncesLegales($siren, 0, 'D', false);
$nbAnn = count($tabAnn);
if (count($tabAnn) > 0) {
$dateAnn = $tabAnn[$nbAnn-1]['dateInsertionSD'];
$dateAnnCompare = DateTime::createFromFormat('Y-m-d H:i:s', $dateAnn);
$dateAnnCompare->add(new DateInterval('P364D'));
if ($dateAnnCompare >= $dateAnnLastCompare) {
$tabRet['SituationJuridique'] = 'D';
}
}
}
} elseif (count($this->getAnnoncesLegales($siren, 0, 'A', false)) > 0) {
$tabRet['SituationJuridique'] = 'A';
} elseif (count($this->getAnnoncesLegales($siren, 0, 'D', false)) > 0) {
$tabRet['SituationJuridique'] = 'D';
}
if ($this->debug) {
file_put_contents('procol.log', "SituationJuridique = ".$tabRet['SituationJuridique']."\n", FILE_APPEND);
}
// Fin Situation Juridique
// Date de dernière mise à jour
$tabAnn = $this->getAnnoncesLegales($siren, 0, '', false, false);
$tabDates=array();
foreach ($tabAnn as $iAnn=>$ann) {
$tabDates[] = $ann['dateInsertionSD'];
}
rsort($tabDates);
$tabRet['dateMajANN'] = Metier_Util_Date::dateT('Y-m-d', 'Y-m-d', $tabDates[0]);
if ($tabRet['dateMajANN'] == '--') {
$tabRet['dateMajANN'] = '';
}
$timer['getAnnoncesLegales']=microtime(true);
$timer['getAnnoncesLegales'] = microtime(true);
}
if (($tabInsee['CJ'] > 0 && $tabInsee['CJ'] < 20

View File

@ -1,5 +1,6 @@
<?php
require_once 'framework/common/curl.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
class Metier_Partenaires_MTva
{
@ -85,19 +86,18 @@ class Metier_Partenaires_MTva
$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($tab) > 0) {
"siren=".$this->siren, false, MYSQL_ASSOC);
if (count($info) > 0) {
$tab = $info[0];
$cle = $tab['cle'];
$dateRef = new DateTime();
$dateRef->sub(new DateInterval('P6M'));
$dateMaj = DateTime::createFromFormat('Ymd', $tab['DateMAJ']);
$this->vatNumber = "FR".$cle.$this->siren;
$this->vatNumber = "FR".$this->cle.$this->siren;
if ($cle !== null) {
$this->vatDefined = true;
return true;
} elseif ($cle === null && $dateMaj >= $dateRef) {
$cle = $this->cle;
$this->vatDefined = false;
return true;
}
@ -141,103 +141,74 @@ class Metier_Partenaires_MTva
*/
protected function getRemoteVAT()
{
$nbIndispo = 0;
while (true) {
$postData = array(
'memberStateCode' => "FR",
'number' => $this->cle.$this->siren,
'traderName' => "",
'traderStreet' => "",
'traderPostalCode' => "",
'traderCity' => "",
'requesterMemberStateCode' => "",
'requesterNumber' => "",
'action' => "check",
'check' => "Vérifier",
);
$tdeb = microtime(true);
$url = 'http://ec.europa.eu/taxation_customs/vies/vatRequest.html';
$referer = 'http://ec.europa.eu/taxation_customs/vies/';
$page = getUrl($url, '', $postData, $referer, false, 'ec.europa.eu', '', 15);
$duree = round(microtime(true)-$tdeb, 3);
if ($page['err_num'] != 0) {
Metier_Util_Log::write('W', 'TVA Erreur CURL n°'. $page['err_num'] .', '. $page['err_msg'] ." sur le Siren $this->siren, numéro de TVA = FR $cle $this->siren. Durée = $duree s !", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
$this->vatNumber = "FR".$this->cle.$this->siren;
$this->vatDefined = false;
$url = 'http://ec.europa.eu/taxation_customs/vies/vatResponse.html';
return true;
}
$client = new Client();
try {
$timeStart = microtime(true);
$response = $client->request('POST', $url, [
'form_params' => [
'memberStateCode' => "FR",
'number' => $this->cle.$this->siren,
'traderName' => "",
'traderStreet' => "",
'traderPostalCode' => "",
'traderCity' => "",
'requesterMemberStateCode' => "",
'requesterNumber' => "",
'action' => "check",
'check' => "Vérifier",
],
]);
$timeStop = microtime(true);
$time = $timeStop - $timeStart;
$code = $page['code'];// Code réponse Serveur
$body = $page['body'];
$header = $page['header'];
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' => $duree
);
if (!$this->iDb->insert('sdv1.siren_tva', $tabInsert)) {
$tabUpdate = array(
'cle' => $this->cle,
'duree' => $duree
);
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 ($duree s) - ERREUR MySql n°". mysql_errno() .' : '. mysql_error(), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
}
}
Metier_Util_Log::write('I', "Siren $this->siren, numéro de TVA = FR $$this->cle $siren ($duree s)", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
$this->vatNumber = "FR".$this->cle.$this->siren;
$this->vatDefined = true;
return true;
} elseif (strpos($body, 'Service non disponible') > 0 || strpos($body, 'ponse trop long.') > 0) {
$nbIndispo++;
if ($nbIndispo < 3) {
Metier_Util_Log::write('I', "TVA Siren $this->siren, Service de l'état membre indisponible. Mise en sommeil...", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
sleep(rand(1, 2));
$nbIndispo = 0;
} else {
$tabInsert = array(
'siren' => $this->siren,
'cle' => 'NULL',
'duree' => $duree
);
$tabUpdate = array(
'cle' => 'NULL',
'duree' => $duree
);
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 ($duree s) - ERREUR MySql n°". mysql_errno() .' : '. mysql_error(), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
if ($response->getStatusCode() == 200) {
$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__);
}
}
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;
}
Metier_Util_Log::write('I', "Siren $this->siren, numéro de TVA = FR $this->cle $this->siren vérification non disponible ($duree s)", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
$this->vatNumber = "FR".$this->cle.$this->siren;
$this->vatDefined = false;
return true;
}
} else {
$tabInsert = array(
'siren' => $this->siren,
'cle' => 'NULL',
'duree' => $duree
);
if (!$this->iDb->insert('sdv1.siren_tva', $tabInsert)) {
$tabUpdate = array(
'cle' => 'NULL',
'duree' => $duree
);
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 ($duree s) - ERREUR MySql n°". mysql_errno() .' : '. mysql_error(), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
}
}
Metier_Util_Log::write('I', "Siren $this->siren, numéro de TVA = FR $this->cle $this->siren non attribué ($duree s)", __LINE__, __FILE__, __FUNCTION__, __CLASS__);
$this->vatNumber = "FR".$this->cle.$this->siren;
$this->vatDefined = false;
}
} catch (RequestException $e) {
Metier_Util_Log::write('I', "TVA ".$e->getMessage(), __LINE__, __FILE__, __FUNCTION__, __CLASS__);
}
return true;
$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__);
}
}
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;
}
/**

View File

@ -543,6 +543,21 @@ class Scores_Extract_Dict
'help' => "",
'columns' => array()
),
'ZonePrioritaire' => array(
'lib' => 'Zone Prioritaire',
'help' => "",
'columns' => array()
),
'AdresseDom'=> array(
'lib' => 'AdresseDom',
'help' => "",
'columns' => array()
),
'Iris'=> array(
'lib' => 'Iris',
'help' => "",
'columns' => array()
),
);
public function __construct()