batch/1.1/old/calculRedevancesTest.php
2013-06-19 08:24:49 +00:00

151 lines
5.9 KiB
PHP

#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
<?php
error_reporting(E_ALL & ~E_NOTICE);
include_once(FWK_PATH.'common/chiffres.php');
include_once(FWK_PATH.'common/dates.php');
include_once(INCLUDE_PATH.'insee/classMInsee.php');
include_once(INCLUDE_PATH.'insee/classMSirene.php');
include_once(INCLUDE_PATH.'partenaires/classMBilans.php');
include_once(INCLUDE_PATH.'partenaires/classMBourse.php');
include_once(INCLUDE_PATH.'partenaires/classMLiens.php');
include_once(INCLUDE_PATH.'scores/classMFinancier.php');
include_once(INCLUDE_PATH.'scores/classMSolvabilite.php');
include_once(INCLUDE_PATH.'partenaires/classMTva.php');
include_once(INCLUDE_PATH.'partenaires/classMMap.php');
include_once(INCLUDE_PATH.'partenaires/classMGreffes.php');
include_once(INCLUDE_PATH.'tmp/configMRatios.php');
include_once(INCLUDE_PATH.'scores/classMScores.php');
include_once(FWK_PATH.'mail/sendMail.php');
include_once(INCLUDE_PATH.'scores/classMRegression.php');
$strInfoScript='Usage : '.basename($argv[0]). " <option>
Calcul des redevances INSEE pour un mois donné.
Options :
-v Mode debug (Verbosité au maximum)
-m:SSAAMM Forcer le mois de calcul des redevances à SSAAMM (sinon mois précedent)
-c:XXX Limiter au client XXX
-t Table de test
";
$tableRdv='inseeRdv';
$argv=$_SERVER['argv'];
//$iDb=new WDB('jo');
$iDb=new WDB('sdv1');
$iDb2=new WDB('sdv1');
$tabUser=array();
$modeDebug=$idClient=false;
$dateMAJ=date('Ymt',mktime(0,0,0,date('m')-1,date('d'),date('Y')));
$strMailInfo='';
for ($i=1,$j=0; isset($argv[$i]); $i++) {
if (substr($argv[$i],0,1)=='-') {
switch (substr($argv[$i],1,1)) {
case 'v': $modeDebug=true; break;
case 'c': $idClient = substr($argv[$i],3)*1; break;
case 'm': $dateMAJ = date('Ymt',mktime(0,0,0,substr($argv[$i],7,2),1,substr($argv[$i],3,4))); break;
case 't': $tableRdv='inseeRdv2'; break;
case '-':
case '?': die($strInfoScript); break;
default: die('Option '. $argv[$i] . " inconnue !\n");
}
}
}
$moisEnCours=substr($dateMAJ,0,6);
$dateDEB=substr($moisEnCours,0,6).'01';
/** Liste des clients **/
if ($idClient) $strClient=" AND id=".$idClient;
else $strClient='';
$tabTmp=$iDb->select('clients', 'id, nom', "1 $strClient", false, MYSQL_ASSOC);
$tabClient=array();
foreach ($tabTmp as $tabTmp2) {
$tabClient[$tabTmp2['id']]=$tabTmp2['nom'];
}
$nbClients=count($tabClient);
/** Liste des utilisateurs **/
if ($idClient) $strClient=" AND idClient=".$idClient;
else $strClient='';
$tabTmp=$iDb->select('utilisateurs', "login, idClient", "1 $strClient", false, MYSQL_ASSOC);
$tabUser=array();
foreach ($tabTmp as $tabTmp2) {
$tabUser['_'.$tabTmp2['login']]=$tabTmp2['idClient'];
}
$nbUsers=count($tabUser);
/** Calcul des redevances en niveau 1 : Navéa (Extranet/WS) **/
$iClient=0;
foreach ($tabClient as $idClient=>$nomClient) {
$iClient++;
echo date('Y/m/d H:i:s')." - Client $iClient/$nbClients - Calcul des redevances type 1 pour '".$tabClient[$idClient]. "' en $moisEnCours : ";
$tabLogs=$iDb->select( 'logs',
'siren, nic/*, date(dateHeure) AS jour*/',
"idClient=$idClient AND page='identite' AND test=0 AND actifInsee IN(0,1) AND source=2 AND dateHeure BETWEEN $dateDEB AND $dateMAJ GROUP BY siren, nic/*, jour*/", false, MYSQL_ASSOC);
$nbSiret=count($tabLogs);
echo "$nbSiret siret".EOL;
$tabInsert=array('idClient'=>$idClient,
'nomClient'=>$tabClient[$idClient],
'mois'=>$moisEnCours,
'produit'=>1,
'nbSiret'=>$nbSiret,
);
if (!$iDb2->insert($tableRdv, $tabInsert, false))
$iDb2->update($tableRdv, $tabInsert, "idClient=$idClient AND mois=$moisEnCours AND produit=1", false);
}
/** Calcul des redevances en niveau 2 : Odéa (Ciblage, sortie prévue en 2012) **/
/** Calcul des redevances en niveau 3 : Sirenages Clients et enrichissement (Depuis Aout 2010) **/
$iClient=0;
foreach ($tabClient as $idClient=>$nomClient) {
$iClient++;
echo date('Y/m/d H:i:s')." - Client $iClient/$nbClients - Calcul des redevances type 3 pour '".$tabClient[$idClient]. "' en $moisEnCours : ";
$tabLogs=$iDb->select( 'jo.sirenage_clients',
'siren, nic, date(dateHeure) AS jour',
"idClient=$idClient AND siren>1000 AND nic>9 AND dateUpdate BETWEEN $dateDEB AND $dateMAJ GROUP BY siren, nic, jour", false, MYSQL_ASSOC);
$nbSiret=count($tabLogs);
echo "$nbSiret siret".EOL;
$tabInsert=array('idClient'=>$idClient,
'nomClient'=>$tabClient[$idClient],
'mois'=>$moisEnCours,
'produit'=>3,
'nbSiret'=>$nbSiret,
);
if (!$iDb2->insert($tableRdv, $tabInsert, false))
$iDb2->update($tableRdv, $tabInsert, "idClient=$idClient AND mois=$moisEnCours AND produit=3", false);
}
/** Calcul des redevances en niveau 4 : Surveillances Insee (Depuis Janvier 2011) **/
$iClient=0;
foreach ($tabClient as $idClient=>$nomClient) {
$iClient++;
echo date('Y/m/d H:i:s')." - Client $iClient/$nbClients - Calcul des redevances type 4 pour '".$tabClient[$idClient]. "' en $moisEnCours : ";
$tabLogs=$iDb->select( 'jo.surveillances_site s, sdv1.utilisateurs u, sdv1.clients c',
's.siren, s.nic, s.dateAjout',
"s.siren>1000 AND s.source='insee' AND s.login=u.login AND u.idClient=$idClient AND u.idClient=c.id and c.test='Non' AND u.typeCompte='PROD' AND s.dateAjout BETWEEN $dateDEB AND $dateMAJ GROUP BY s.siren, s.nic, s.dateAjout", false, MYSQL_ASSOC);
$nbSiret=count($tabLogs);
echo "$nbSiret siret".EOL;
$tabInsert=array('idClient'=>$idClient,
'nomClient'=>$tabClient[$idClient],
'mois'=>$moisEnCours,
'produit'=>4,
'nbSiret'=>$nbSiret,
);
if (!$iDb2->insert($tableRdv, $tabInsert, false))
$iDb2->update($tableRdv, $tabInsert, "idClient=$idClient AND mois=$moisEnCours AND produit=4", false);
}
/** Calcul des redevances en niveau 5 : INEXISTANT **/
die();
?>