Librairies Update

This commit is contained in:
Michael RICOIS 2016-08-03 16:56:07 +02:00
parent 6f8da88cab
commit f74b432bf3
7 changed files with 333 additions and 218 deletions

View File

@ -111,62 +111,77 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
if (!empty($nic)) { if (!empty($nic)) {
$nic = str_pad($nic, 5, '0', STR_PAD_LEFT); $nic = str_pad($nic, 5, '0', STR_PAD_LEFT);
} }
if (!Metier_Util_String::valideData($siren, 9, 9,'N')) //Siren non précisé ou incorrect. //Siren non précisé ou incorrect.
if (!Metier_Util_String::valideData($siren, 9, 9,'N')) {
return $erreur; return $erreur;
elseif ($siren*1==0) // Siren vide }
// Siren vide
elseif (intval($siren) == 0) {
return $erreur; return $erreur;
else }
{ else {
if (!isset($nic) || trim($nic)=='') if (!isset($nic) || trim($nic)=='') {
{
$somme = 0; $somme = 0;
for ($i=0; $i<=8; $i+=2) // Traitement IMPAIR // Traitement IMPAIR
for ($i=0; $i<=8; $i+=2) {
$somme+= (integer) substr($siren,$i,1); $somme+= (integer) substr($siren,$i,1);
}
for ($i=1; $i<=7; $i+=2) // Traitement PAIR
{ // Traitement PAIR for ($i=1; $i<=7; $i+=2) {
$var_tmp = (string) (2*((integer)substr($siren,$i,1))); $var_tmp = (string) (2*((integer)substr($siren,$i,1)));
$som_tmp = 0; $som_tmp = 0;
for($j=0;$j<strlen($var_tmp);$j++) for($j=0; $j<strlen($var_tmp);$j++) {
$som_tmp+= (integer)substr($var_tmp,$j,1); $som_tmp+= (integer)substr($var_tmp,$j,1);
}
$somme+= $som_tmp; $somme+= $som_tmp;
} }
if ((integer)($somme/10)!=($somme/10)) // Le Siren est faux
{ // Le Siren est faux if ((integer) ($somme/10) != ($somme/10)) {
if (substr($siren,0,3)!='200') // Les siren débutant par 200 sont toujours valides (sirens provisoires de la BDF?!) // Les siren débutant par 200 sont toujours valides (sirens provisoires de la BDF?!)
if (substr($siren,0,3) != '200') {
return $erreur; return $erreur;
} }
} else { }
if (!Metier_Util_String::valideData($nic,1,5,'N')) // Nic de format incorrect. }
else {
// Nic de format incorrect.
if (!Metier_Util_String::valideData($nic,1,5,'N')) {
return $erreur; return $erreur;
}
$SIRET = $siren.$nic; $SIRET = $siren.$nic;
if ($siren<>356000000) { if ($siren != 356000000) {
$somme=0; $somme=0;
for ($i=0; $i<=12; $i+=2) // Traitement PAIR
{ // Traitement PAIR for ($i=0; $i<=12; $i+=2) {
$var_tmp = (string) (2*((integer)substr($SIRET,$i,1))); $var_tmp = (string) (2*((integer)substr($SIRET,$i,1)));
$som_tmp = 0; $som_tmp = 0;
for($j=0;$j<strlen($var_tmp);$j++) for($j=0; $j<strlen($var_tmp); $j++) {
$som_tmp+= (integer) substr($var_tmp,$j,1); $som_tmp+= (integer) substr($var_tmp,$j,1);
}
$somme+= $som_tmp; $somme+= $som_tmp;
} }
for ($i=1; $i<=13; $i+=2) // Traitement IMPAIR // Traitement IMPAIR
for ($i=1; $i<=13; $i+=2) {
$somme+= (integer) substr($SIRET,$i,1); $somme+= (integer) substr($SIRET,$i,1);
}
if ((integer)($somme/10)!=($somme/10))// Le Siret est faux // Le Siret est faux
if ((integer) ($somme/10) != ($somme/10)) {
return $erreur; return $erreur;
}
} else { } else {
// Cas particulier du siren de LA POSTE : 356 000 000 00000 // Cas particulier du siren de LA POSTE : 356 000 000 00000
$somme = 14; $somme = 14;
for ($i=9; $i<=13; $i++) for ($i=9; $i<=13; $i++) {
$somme+= (integer)substr($SIRET,$i,1); $somme+= (integer)substr($SIRET,$i,1);
if ($somme%5!=0) // Le NIC de l'établissement de LA POSTE est faux ! }
// Le NIC de l'établissement de LA POSTE est faux !
if ($somme%5 != 0) {
return $erreur; return $erreur;
} }
} }
} }
}
return true; return true;
} }

View File

@ -408,8 +408,8 @@ class Metier_Partenaires_MBilans
return $this->Bilans[$typeBilan.$millesime]; return $this->Bilans[$typeBilan.$millesime];
} }
$clotureDate = new Zend_Date($millesime, 'dd/MM/yyyy'); $clotureDate = DateTime::createFromFormat('d/m/Y', $millesime);
$clotureDateSql = $clotureDate->toString('yyyyMMdd'); $clotureDateSql = $clotureDate->format('Ymd');
if ($accesPartenaire) { if ($accesPartenaire) {
// On ne veut pas de bilans "Téléchargés" directement sur Internet // On ne veut pas de bilans "Téléchargés" directement sur Internet
$strSansBilansWeb=' AND partenaire<>7 '; $strSansBilansWeb=' AND partenaire<>7 ';
@ -550,8 +550,8 @@ class Metier_Partenaires_MBilans
|| ( ($tabBilan['N15']*1==0 || $tabBilan['N32']*1==0) && $tabBilan['CONSOLIDE']=='S' ) // Réel Simplifié || ( ($tabBilan['N15']*1==0 || $tabBilan['N32']*1==0) && $tabBilan['CONSOLIDE']=='S' ) // Réel Simplifié
) { ) {
$cloturePreDate = $clotureDate->subMonth($bilan['dureeExercice']); $cloturePreDate = $clotureDate->sub(new DateInterval('P'.$bilan['dureeExercice'].'M'));
$cloturePreDateSql = $cloturePreDate->toString('yyyyMM'); $cloturePreDateSql = $cloturePreDate->format('Ym');
// --- Recherche des infos du bilan précédent // --- Recherche des infos du bilan précédent
$ret = $this->iDb->select('jo.bilans', $ret = $this->iDb->select('jo.bilans',

View File

@ -198,6 +198,27 @@ class Metier_Partenaires_MCadastre
return $lib; return $lib;
} }
/**
* Nature des locaux ou parcelles
* @param string $code
* @param string $type
* @return string
*/
public function getNatureLabel($code, $type = 'local')
{
if ($type == 'local') {
if (array_key_exists($code, self::$PEV)) {
return self::$PEV[$code];
}
} elseif ($type == 'parcelle') {
if (array_key_exists($code, self::$natureParcelles)) {
return self::$natureParcelles[$code];
}
}
return '';
}
/** /**
* Locaux : Propriétés baties * Locaux : Propriétés baties
* @param string $siren * @param string $siren
@ -234,7 +255,7 @@ class Metier_Partenaires_MCadastre
'pmAdrDep' => trim($loc['CCODEP']), 'pmAdrDep' => trim($loc['CCODEP']),
'pmAdrCom' => trim($loc['companyCCOCOM']), 'pmAdrCom' => trim($loc['companyCCOCOM']),
'localDroit' => trim($loc['CCODRO']), 'localDroit' => trim($loc['CCODRO']),
'localDroitLib' => self::$tabCodeDroit[trim($loc['CCODRO'])], 'localDroitLib' => self::$codeDroit[trim($loc['CCODRO'])],
'localDep' => trim($loc['CCODEP']), 'localDep' => trim($loc['CCODEP']),
'localCom' => trim($loc['CCOCOM']), 'localCom' => trim($loc['CCOCOM']),
'localComLib' => trim($loc['DLICOM']), 'localComLib' => trim($loc['DLICOM']),
@ -346,4 +367,110 @@ class Metier_Partenaires_MCadastre
return $parcelles; return $parcelles;
} }
/**
* List des éléments du patrimoine
* @return array
*/
public function patrimoine()
{
$locauxSql = "SELECT 'local' AS type, " .
"l.CCODRO AS role, " .
"l.DNUVOI AS adresseNum, " .
"l.DLTNUV AS adresseInd, " .
"l.CNAVOI AS adresseType, " .
"l.DLIVOI AS adresseLib, " .
"l.CCODEP AS departement, " .
"l.CCOCOM AS communeCode, " .
"l.DLICOM AS communeLib, " .
"l.CCOSEC AS section, " .
"l.DNUPLA AS planNum, " .
"l.CCORIV AS fantoir, " .
"l.DNUBAT AS batiment, " .
"l.DESC AS ent, " .
"l.DNIV AS niveau, " .
"(l.DSUPOD0 + l.DSUPOD1 + l.DSUPOD2 + l.DSUPOD3 + l.DSUPOD4 + l.DSUPOD5 + l.DSUPOD7 + l.DSUPOD8 + l.DSUPOD9) AS surfaceTotal, " .
"l.CCOAFF0 AS nature0, " .
"l.DSUPOD0 AS surface0, " .
"l.CCOAFF1 AS nature1, " .
"l.DSUPOD1 AS surface1, " .
"l.CCOAFF2 AS nature2, " .
"l.DSUPOD2 AS surface2, " .
"l.CCOAFF3 AS nature3, " .
"l.DSUPOD3 AS surface3, " .
"l.CCOAFF4 AS nature4, " .
"l.DSUPOD4 AS surface4, " .
"l.CCOAFF5 AS nature5, " .
"l.DSUPOD5 AS surface5, " .
"l.CCOAFF6 AS nature6, " .
"l.DSUPOD6 AS surface6, " .
"l.CCOAFF7 AS nature7, " .
"l.DSUPOD7 AS surface7, " .
"l.CCOAFF8 AS nature8, " .
"l.DSUPOD8 AS surface8, " .
"l.CCOAFF9 AS nature9, " .
"l.DSUPOD9 AS surface9, " .
"l.dateInsert " .
"FROM sdv1.cad_perloc l, sdv1.cad_permor e " .
"WHERE e.DSIREN='$this->siren' AND e.INTCIF=l.INTCIF AND e.DNUPER=l.DNUPER";
$parcellesSql = "SELECT 'parcelle' AS type, " .
"p.CCODRO AS role, " .
"p.DNUVOI AS adresseNum, " .
"p.DLTNUV AS adresseInd, " .
"p.CNAVOI AS adresseType, " .
"p.DLIVOI AS adresseLib ," .
"p.CCODEP AS departement, " .
"p.CCOCOM AS communeCode, " .
"p.DLICOM AS communeLib, " .
"p.CCOSEC AS section, " .
"p.DNUPLA AS planNum, " .
"p.CCORIV AS fantoir, " .
"'' AS batiment, " .
"'' AS ent, " .
"'' AS niveau, " .
"p.DCNPAR AS surfaceTotal, " .
"p.DSGRPF0 AS nature0, " .
"p.DCNSUF0 AS surface0, " .
"p.DSGRPF1 AS nature1, " .
"p.DCNSUF1 AS surface1, " .
"p.DSGRPF2 AS nature2, " .
"p.DCNSUF2 AS surface2, " .
"p.DSGRPF3 AS nature3, " .
"p.DCNSUF3 AS surface3, " .
"p.DSGRPF4 AS nature4, " .
"p.DCNSUF4 AS surface4, " .
"p.DSGRPF5 AS nature5, " .
"p.DCNSUF5 AS surface5, " .
"p.DSGRPF6 AS nature6, " .
"p.DCNSUF6 AS surface6, " .
"p.DSGRPF7 AS nature7, " .
"p.DCNSUF7 AS surface7, " .
"p.DSGRPF8 AS nature8, " .
"p.DCNSUF8 AS surface8, " .
"p.DSGRPF9 AS nature9, " .
"p.DCNSUF9 AS surface9, " .
"p.dateInsert " .
"FROM sdv1.cad_perpar p, sdv1.cad_permor e " .
"WHERE e.DSIREN='$this->siren' AND e.INTCIF=p.INTCIF AND e.DNUPER=p.DNUPER";
$sql = "SELECT * FROM ( ($locauxSql) UNION ALL ($parcellesSql) ) results";
$db = Zend_Db_Table::getDefaultAdapter();
//$results = $this->iDb->query($sql, true);
$results = $db->fetchAll($sql, null, Zend_Db::FETCH_ASSOC);
$list = array();
if (count($results) > 0) {
foreach ($results as $result) {
// Libellé role
$result['roleLib'] = self::$codeDroit[trim($result['role'])];
$list[] = $result;
}
}
return $list;
}
} }

View File

@ -186,82 +186,90 @@ class Metier_Partenaires_MTva
} }
/** Test de la validité du siren demandé /**
** @param int SIREN à tester * Test de la validité du siren demandé
** @param int NIC (facultatif) * @param int SIREN à tester
** @param mixed Message textuel d'erreur à afficher en cas d'erreur ou false * @param int NIC (facultatif)
** @return mixed true, false ou Message d'erreur passé en paramètre * @param mixed Message textuel d'erreur à afficher en cas d'erreur ou false
**/ * @return mixed true, false ou Message d'erreur passé en paramètre
private function valideSiren($siren, $nic='', $erreur=false) { */
private function valideSiren($siren, $nic='', $erreur=false)
/** Si le siren est de taille < à 9, on ajoute des 0 significatifs **/
switch (strlen($siren)) {
case 1: $siren='00000000'.$siren; break;
case 2: $siren='0000000'.$siren; break;
case 3: $siren='000000'.$siren; break;
case 4: $siren='00000'.$siren; break;
case 5: $siren='0000'.$siren; break;
case 6: $siren='000'.$siren; break;
case 7: $siren='00'.$siren; break;
case 8: $siren='0'.$siren; break;
}
if (strlen($nic)>0) {
switch (strlen($nic)) {
case 1: $nic='0000'.$nic; break;
case 2: $nic='000'.$nic; break;
case 3: $nic='00'.$nic; break;
case 4: $nic='0'.$nic; break;
}
}
if (!Metier_Util_String::valideData($siren, 9, 9,'N')) //Siren non précisé ou incorrect.
return $erreur;
elseif ($siren*1==0) // Siren vide
return $erreur;
else
{
if (!isset($nic) || trim($nic)=='')
{ {
$siren = str_pad($siren, 9, '0', STR_PAD_LEFT);
if (!empty($nic)) {
$nic = str_pad($nic, 5, '0', STR_PAD_LEFT);
}
//Siren non précisé ou incorrect.
if (!Metier_Util_String::valideData($siren, 9, 9,'N')) {
return $erreur;
}
// Siren vide
elseif (intval($siren) == 0) {
return $erreur;
}
else {
if (!isset($nic) || trim($nic)=='') {
$somme = 0; $somme = 0;
for ($i=0; $i<=8; $i+=2) // Traitement IMPAIR // Traitement IMPAIR
for ($i=0; $i<=8; $i+=2) {
$somme+= (integer) substr($siren,$i,1); $somme+= (integer) substr($siren,$i,1);
}
for ($i=1; $i<=7; $i+=2) // Traitement PAIR
{ // Traitement PAIR for ($i=1; $i<=7; $i+=2) {
$var_tmp = (string) (2*((integer)substr($siren,$i,1))); $var_tmp = (string) (2*((integer)substr($siren,$i,1)));
$som_tmp = 0; $som_tmp = 0;
for($j=0;$j<strlen($var_tmp);$j++) for($j=0; $j<strlen($var_tmp);$j++) {
$som_tmp+= (integer)substr($var_tmp,$j,1); $som_tmp+= (integer)substr($var_tmp,$j,1);
}
$somme+= $som_tmp; $somme+= $som_tmp;
} }
if ((integer)($somme/10)!=($somme/10)) // Le Siren est faux
{ // Le Siren est faux if ((integer) ($somme/10) != ($somme/10)) {
if (substr($siren,0,3)!='200') // Les siren débutant par 200 sont toujours valides (sirens provisoires de la BDF?!) // Les siren débutant par 200 sont toujours valides (sirens provisoires de la BDF?!)
if (substr($siren,0,3) != '200') {
return $erreur;
}
}
}
else {
// Nic de format incorrect.
if (!Metier_Util_String::valideData($nic,1,5,'N')) {
return $erreur;
}
$SIRET = $siren.$nic;
if ($siren != 356000000) {
$somme=0;
// Traitement PAIR
for ($i=0; $i<=12; $i+=2) {
$var_tmp = (string) (2*((integer)substr($SIRET,$i,1)));
$som_tmp = 0;
for($j=0; $j<strlen($var_tmp); $j++) {
$som_tmp+= (integer) substr($var_tmp,$j,1);
}
$somme+= $som_tmp;
}
// Traitement IMPAIR
for ($i=1; $i<=13; $i+=2) {
$somme+= (integer) substr($SIRET,$i,1);
}
// Le Siret est faux
if ((integer) ($somme/10) != ($somme/10)) {
return $erreur; return $erreur;
} }
} else { } else {
if (!Metier_Util_String::valideData($nic,1,5,'N')) // Nic de format incorrect. // Cas particulier du siren de LA POSTE : 356 000 000 00000
return $erreur; $somme = 14;
for ($i=9; $i<=13; $i++) {
$SIRET=$siren.$nic;
$somme=0;
for ($i=0; $i<=12; $i+=2)
{ // Traitement PAIR
$var_tmp=(string)(2*((integer)substr($SIRET,$i,1)));
$som_tmp=0;
for($j=0;$j<strlen($var_tmp);$j++)
$som_tmp+=(integer)substr($var_tmp,$j,1);
$somme+=$som_tmp;
}
for ($i=1; $i<=13; $i+=2) // Traitement IMPAIR
$somme+= (integer)substr($SIRET,$i,1); $somme+= (integer)substr($SIRET,$i,1);
}
if ((integer)($somme/10)!=($somme/10))// Le Siret est faux // Le NIC de l'établissement de LA POSTE est faux !
if ($somme%5 != 0) {
return $erreur; return $erreur;
} }
} }
}
}
return true; return true;
} }
} }

View File

@ -3913,16 +3913,10 @@ function calculIndiScore($siren, $nic=0, $accesDist=false, $cycleClient=2, $mail
$EffectifEn = $tabIdentite['Effectif']; $EffectifEn = $tabIdentite['Effectif'];
$bilanAgeMax = 3 * 12; //Age maximum du dernier bilan en mois $bilanAgeMax = 3 * 12; //Age maximum du dernier bilan en mois
if (!empty($tabIdentite['bilanDate']) && intval($tabIdentite['bilanYP'])>0 ) { if (!empty($tabIdentite['bilanDate']) && intval($tabIdentite['bilanYP'])>0 ) {
$dateBilan = DateTime::createFromFormat('Ymd', $tabIdentite['bilanDate']);
Zend_Date::setOptions(array('extend_month' => true)); $dateCompare = new DateTime();
$dateBilan = new Zend_Date($tabIdentite['bilanDate'], 'yyyyMMdd'); $dateCompare->sub(new DateInterval('P'.$bilanAgeMax.'M'));
$dateNow = new Zend_Date(); if ($dateBilan > $dateCompare) {
$difference = $dateNow->sub($dateBilan);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND);
$measure->convertTo(Zend_Measure_Time::MONTH);
$nbMonth = $measure->getValue();
if ( $nbMonth < $bilanAgeMax ) {
$EffectifEn = $tabIdentite['bilanYP']; $EffectifEn = $tabIdentite['bilanYP'];
} }
} }

View File

@ -3891,16 +3891,10 @@ class SdMetier_Scoring_Base extends SdMetier_Scoring_Vars
$EffectifEn = $tabIdentite['Effectif']; $EffectifEn = $tabIdentite['Effectif'];
$bilanAgeMax = 3 * 12; //Age maximum du dernier bilan en mois $bilanAgeMax = 3 * 12; //Age maximum du dernier bilan en mois
if (!empty($tabIdentite['bilanDate']) && intval($tabIdentite['bilanYP'])>0 ) { if (!empty($tabIdentite['bilanDate']) && intval($tabIdentite['bilanYP'])>0 ) {
$dateBilan = DateTime::createFromFormat('Ymd', $tabIdentite['bilanDate']);
Zend_Date::setOptions(array('extend_month' => true)); $dateCompare = new DateTime();
$dateBilan = new Zend_Date($tabIdentite['bilanDate'], 'yyyyMMdd'); $dateCompare->sub(new DateInterval('P'.$bilanAgeMax.'M'));
$dateNow = new Zend_Date(); if ($dateBilan > $dateCompare) {
$difference = $dateNow->sub($dateBilan);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND);
$measure->convertTo(Zend_Measure_Time::MONTH);
$nbMonth = $measure->getValue();
if ( $nbMonth < $bilanAgeMax ) {
$EffectifEn = $tabIdentite['bilanYP']; $EffectifEn = $tabIdentite['bilanYP'];
} }
} }

View File

@ -430,18 +430,14 @@ class SdMetier_Sfr_Scoring
public function evaluate($siren) public function evaluate($siren)
{ {
Zend_Date::setOptions(array('extend_month' => true));
if ($this->debug) file_put_contents('sfr.log', "SIREN = $siren\n", FILE_APPEND); if ($this->debug) file_put_contents('sfr.log', "SIREN = $siren\n", FILE_APPEND);
//Set ValContratAge //Set ValContratAge
if ( !empty($this->ValContratDate) ) { if ( !empty($this->ValContratDate) ) {
$dateContrat = new Zend_Date($this->ValContratDate, 'yyyyMMdd'); $dateContrat = DateTime::createFromFormat('Ymd', $this->ValContratDate);
$dateNow = new Zend_Date(); $dateNow = new DateTime();
$diff = $dateNow->sub($dateContrat); $interval = $dateNow->diff($dateContrat);
$measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $this->ValContratAge = $interval->format('%y') * 12 + $interval->format('%m');
$measure->convertTo(Zend_Measure_Time::MONTH);
$this->ValContratAge = $measure->getValue();
} }
$classInsee = new Metier_Insee_MInsee(); $classInsee = new Metier_Insee_MInsee();
@ -467,16 +463,14 @@ class SdMetier_Sfr_Scoring
if ( $result !== null ) { if ( $result !== null ) {
//Indiscore - aller chercher scores dans l'historique moins de X mois //Indiscore - aller chercher scores dans l'historique moins de X mois
$dateUpdate = new Zend_Date(substr($result->dateUpdate,0,10), 'yyyy-MM-dd'); $dateUpdate = DateTime::createFromFormat('Y-m-d', substr($result->dateUpdate,0,10));
$dateNow = new DateTime();
$interval = $dateNow->diff($dateUpdate);
$diff = $interval->format('%y') * 12 + $interval->format('%m');
$dateNow = new Zend_Date(); if ($this->debug) file_put_contents('sfr.log', "INDISCORE DIFF = " . $diff . "\n", FILE_APPEND);
$diffUpdate = $dateNow->sub($dateUpdate);
$measureUpdate = new Zend_Measure_Time($diffUpdate->toValue(), Zend_Measure_Time::SECOND);
$measureUpdate->convertTo(Zend_Measure_Time::MONTH);
if ($this->debug) file_put_contents('sfr.log', "INDISCORE DIFF = " . $measureUpdate->getValue() . "\n", FILE_APPEND); if ( $diff <= 12 ) {
if ( $measureUpdate->getValue() <= 12 ) {
$this->ValIndiscore = $result->indiScore20; $this->ValIndiscore = $result->indiScore20;
$this->ValDateCalculIndiscore = $result->indiScoreDate; $this->ValDateCalculIndiscore = $result->indiScoreDate;
} }
@ -488,21 +482,17 @@ class SdMetier_Sfr_Scoring
if ( !empty($result->dateCrea) && $result->dateCrea!='0000-00-00 00:00:00' ) { if ( !empty($result->dateCrea) && $result->dateCrea!='0000-00-00 00:00:00' ) {
$dateC = new Zend_Date($result->dateCrea, 'yyyy-MM-dd'); $dateC = DateTime::createFromFormat('Y-m-d', $result->dateCrea);
$dateNow = new Zend_Date(); $dateNow = new DateTime();
$difference = $dateNow->sub($dateC); $interval = $dateNow->diff($dateC);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); $this->ValInseeAge = $interval->format('%y') * 12 + $interval->format('%m');
$measure->convertTo(Zend_Measure_Time::MONTH);
$this->ValInseeAge = $measure->getValue();
} elseif ( !empty($result->dateImmat) && $result->dateImmat!='0000-00-00 00:00:00' ) { } elseif ( !empty($result->dateImmat) && $result->dateImmat!='0000-00-00 00:00:00' ) {
$dateC = new Zend_Date($result->dateImmat, 'yyyy-MM-dd'); $dateC = DateTime::createFromFormat('Y-m-d', $result->dateImmat);
$dateNow = new Zend_Date(); $dateNow = new DateTime();
$difference = $dateNow->sub($dateC); $interval = $dateNow->diff($dateC);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); $this->ValInseeAge = $interval->format('%y') * 12 + $interval->format('%m');
$measure->convertTo(Zend_Measure_Time::MONTH);
$this->ValInseeAge = $measure->getValue();
} }
@ -536,17 +526,14 @@ class SdMetier_Sfr_Scoring
$bilanAgeMax = 3*12; //Age maximum du dernier bilan en mois $bilanAgeMax = 3*12; //Age maximum du dernier bilan en mois
if (!empty($identite['bilanDate']) && intval($identite['bilanYP'])>0 ) { if (!empty($identite['bilanDate']) && intval($identite['bilanYP'])>0 ) {
$dateBilan = new Zend_Date($identite['bilanDate'], 'yyyyMMdd'); $dateBilan = DateTime::createFromFormat('Ymd', $identite['bilanDate']);
$dateNow = new Zend_Date(); $dateCompare = new DateTime();
$difference = $dateNow->sub($dateBilan); $dateCompare->sub(new DateInterval('P'.$bilanAgeMax.'M'));
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); if ($dateBilan > $dateCompare) {
$measure->convertTo(Zend_Measure_Time::MONTH);
$nbMonth = $measure->getValue();
if ( $nbMonth < $bilanAgeMax ) {
$this->ValEffectif = $identite['bilanYP']; $this->ValEffectif = $identite['bilanYP'];
} }
if ($this->debug) file_put_contents('sfr.log', "Bilan : nbMonth = ".$nbMonth."\n", FILE_APPEND);
if ($this->debug) file_put_contents('sfr.log', "Bilan : ".$dateBilan->format('Ymd')." > ".$dateCompare->format('Ymd')."\n", FILE_APPEND);
} }
if ($this->debug) file_put_contents('sfr.log', "ValEffectif = ".$this->ValEffectif."\n", FILE_APPEND); if ($this->debug) file_put_contents('sfr.log', "ValEffectif = ".$this->ValEffectif."\n", FILE_APPEND);
@ -556,27 +543,22 @@ class SdMetier_Sfr_Scoring
//Age de l'entreprise en mois //Age de l'entreprise en mois
if ( !empty($identite['DateCreaEn']) && $identite['DateCreaEn']!='0000-00-00 00:00:00' ) { if ( !empty($identite['DateCreaEn']) && $identite['DateCreaEn']!='0000-00-00 00:00:00' ) {
$dateC = new Zend_Date($identite['DateCreaEn'], 'yyyy-MM-dd'); $dateC = DateTime::createFromFormat('Y-m-d', $identite['DateCreaEn']);
$dateNow = new Zend_Date(); $dateNow = new DateTime();
$difference = $dateNow->sub($dateC); $interval = $dateNow->diff($dateC);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); $this->ValInseeAge = $interval->format('%y') * 12 + $interval->format('%m');
$measure->convertTo(Zend_Measure_Time::MONTH);
$this->ValInseeAge = $measure->getValue();
} elseif ( !empty($identite['dateImmat']) && $identite['dateImmat']!='0000-00-00 00:00:00' ) { } elseif ( !empty($identite['dateImmat']) && $identite['dateImmat']!='0000-00-00 00:00:00' ) {
$dateC = new Zend_Date($identite['dateImmat'], 'yyyy-MM-dd'); $dateC = DateTime::createFromFormat('Y-m-d', $identite['dateImmat']);
$dateNow = new Zend_Date(); $dateNow = new DateTime();
$difference = $dateNow->sub($dateC); $interval = $dateNow->diff($dateC);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); $this->ValInseeAge = $interval->format('%y') * 12 + $interval->format('%m');
$measure->convertTo(Zend_Measure_Time::MONTH);
$this->ValInseeAge = $measure->getValue();
} }
if ($this->debug) file_put_contents('sfr.log', "ValInseeAge = ".$this->ValInseeAge."\n", FILE_APPEND); if ($this->debug) file_put_contents('sfr.log', "ValInseeAge = ".$this->ValInseeAge."\n", FILE_APPEND);
$this->ValSituationJuridique = $identite['SituationJuridique']; $this->ValSituationJuridique = $identite['SituationJuridique'];
} }
} }
@ -587,35 +569,30 @@ class SdMetier_Sfr_Scoring
//Age de l'entreprise en mois //Age de l'entreprise en mois
if ( !empty($this->ValDateCrea) && $this->ValDateCrea!='0000-00-00 00:00:00' ) { if ( !empty($this->ValDateCrea) && $this->ValDateCrea!='0000-00-00 00:00:00' ) {
$dateC = new Zend_Date($this->ValDateCrea, 'yyyy-MM-dd'); $dateC = DateTime::createFromFormat('Y-m-d', $this->ValDateCrea);
$dateNow = new Zend_Date(); $dateNow = new DateTime();
$difference = $dateNow->sub($dateC); $interval = $dateNow->diff($dateC);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); $this->ValInseeAge = $interval->format('%y') * 12 + $interval->format('%m');
$measure->convertTo(Zend_Measure_Time::MONTH);
$this->ValInseeAge = $measure->getValue();
} elseif ( !empty($this->ValDateImmat) && $this->ValDateImmat!='0000-00-00 00:00:00' ) { } elseif ( !empty($this->ValDateImmat) && $this->ValDateImmat!='0000-00-00 00:00:00' ) {
$dateC = new Zend_Date($this->ValDateImmat, 'yyyy-MM-dd'); $dateC = DateTime::createFromFormat('Y-m-d', $this->ValDateImmat);
$dateNow = new Zend_Date(); $dateNow = new DateTime();
$difference = $dateNow->sub($dateC); $interval = $dateNow->diff($dateC);
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); $this->ValInseeAge = $interval->format('%y') * 12 + $interval->format('%m');
$measure->convertTo(Zend_Measure_Time::MONTH);
$this->ValInseeAge = $measure->getValue();
} }
if ($this->debug) file_put_contents('sfr.log', "ValInseeAge = ".$this->ValInseeAge."\n", FILE_APPEND); if ($this->debug) file_put_contents('sfr.log', "ValInseeAge = ".$this->ValInseeAge."\n", FILE_APPEND);
//Vérification validité du score //Vérification validité du score
$dateNow = new Zend_Date(); $dateUpdate = DateTime::createFromFormat('Y-m-d', substr($this->ValDateUpdate,0,10));
$dateUpdate = new Zend_Date(substr($this->ValDateUpdate,0,10), 'yyyy-MM-dd'); $dateNow = new DateTime();
$diffUpdate = $dateNow->sub($dateUpdate); $interval = $dateNow->diff($dateUpdate);
$measureUpdate = new Zend_Measure_Time($diffUpdate->toValue(), Zend_Measure_Time::SECOND); $diff = $interval->format('%y') * 12 + $interval->format('%m');
$measureUpdate->convertTo(Zend_Measure_Time::MONTH);
if ($this->debug) file_put_contents('sfr.log', "INDISCORE DIFF = " . $measureUpdate->getValue() . "\n", FILE_APPEND); if ($this->debug) file_put_contents('sfr.log', "INDISCORE DIFF = " . $diff . "\n", FILE_APPEND);
if ( $measureUpdate->getValue() > 12 ) { if ( $diff > 12 ) {
$this->ValIndiscore = null; $this->ValIndiscore = null;
$this->ValDateCalculIndiscore = null; $this->ValDateCalculIndiscore = null;
} }