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

942 lines
17 KiB
PHP

#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
<?php
function wsLog($service, $siret='', $ref='') {
/* if (strlen($siret)==14) {
$siren=substr($siret,0,9);
$nic=substr($siret,9,5);
} elseif (strlen($siret)==9) {
$siren=$siret;
$nic='';
}
global $iDbCrm, $tabInfoUser;
$tabInsert=array( 'login'=>$tabInfoUser['login'],
'page'=>$service,
'siren'=>$siren,
'nic'=>$nic,
'params'=>$ref);
$rep=$iDbCrm->insert('logs', $tabInsert);
*/
}
error_reporting(E_ALL & ~E_NOTICE);
include_once(FWK_PATH.'common/chiffres.php');
include_once(FWK_PATH.'common/dates.php');
include_once('/var/www/html/ws/WsEntreprise.php');
$nbExercices=1;
$strInfoScript='Usage : '.basename($argv[0]). " [OPTION]
Scorer toute la base entreprise S&D.
Options :
-t Calculer tous les scores (*)
-i:XXX Reprendre à la ligne XXX
(*) Option par défaut si aucun argument n'est passé.
";/* -e:X Calculer pour les X derniers exercices (3 par défaut)
-f Calculer les scores financiers
*/
for ($i=1; isset($argv[$i]); $i++) {
if (substr($argv[$i],0,1)=='-') {
switch (substr($argv[$i],1,1)) {
case 't':
case 'T':
break;
case 'i':
case 'I':
$iDeb=substr($argv[$i],3);
break;
case '-':
case '?':
die($strInfoScript);
break;
default:
die('Option '. $argv[$i] . ' inconnue !'.EOL);
break;
}
}
}
$iDbI=new WDB('insee');
$iDb=new WDB('modelisation');
$iWs=new WsEntreprise();
echo date('Y/m/d - H:i:s') ." - DEBUT du programme de calcul des scores...".EOL;
echo date('Y/m/d - H:i:s') ." - Calcul des scores financiers...".EOL;
set_time_limit(0);
$tabSiren=array(
'300990454',
'301500351',
'301768107',
'302355540',
'302701511',
'303292460',
'304887086',
'306302803',
'309423036',
'310228366',
'310410469',
'310682596',
'310810155',
'311531776',
'311658702',
'312277692',
'312783574',
'314087610',
'315615245',
'316833987',
'317327898',
'317886653',
'319188132',
'319648242',
'320252190',
'322474859',
'322497140',
'322856329',
'323005330',
'323341024',
'323512152',
'323858217',
'323877779',
'324719954',
'325227684',
'325330322',
'325942720',
'326195138',
'326306743',
'326803145',
'327052650',
'327178364',
'327395455',
'327467783',
'327858403',
'328691324',
'328898077',
'328930664',
'329147441',
'329152672',
'329220859',
'329301188',
'329582704',
'329765036',
'329929251',
'330549221',
'330646779',
'330709684',
'330968959',
'331270876',
'331287920',
'332081017',
'332138767',
'332452515',
'332985233',
'333538387',
'333590271',
'333662377',
'334025913',
'334026630',
'334173028',
'334736345',
'337534812',
'337692388',
'338002777',
'338341472',
'339579955',
'339797516',
'339822363',
'339861544',
'340832872',
'340861251',
'341363422',
'341736874',
'341992329',
'342031929',
'342119054',
'342233756',
'342738507',
'343208377',
'343925947',
'344131180',
'344673090',
'344796032',
'344825864',
'347645301',
'348554650',
'348697376',
'348809740',
'348896655',
'349443887',
'349727784',
'349731653',
'349735787',
'349881847',
'350070165',
'350105748',
'350316337',
'350417101',
'350657300',
'351226469',
'351821418',
'352295216',
'352700843',
'353082415',
'353186513',
'353442114',
'353486095',
'353635683',
'353712623',
'353770571',
'353911704',
'359800828',
'377514682',
'377601380',
'377601810',
'377876594',
'378507511',
'378530521',
'378801419',
'378895346',
'379021272',
'379024961',
'379038409',
'379294192',
'380117671',
'380149427',
'380605717',
'380776377',
'381266345',
'381513498',
'381613256',
'381838598',
'381913524',
'382793230',
'382802551',
'382845618',
'382950152',
'383597358',
'384021747',
'384259909',
'384919056',
'384979787',
'385007224',
'385039136',
'385112487',
'385331954',
'385384094',
'387453798',
'387619752',
'387734841',
'387803851',
'387861016',
'387900673',
'388241184',
'388268765',
'388273427',
'388335986',
'388372252',
'388390932',
'388410706',
'388441073',
'388748972',
'388852337',
'389016262',
'389379736',
'389809989',
'389883281',
'390310969',
'390311132',
'390570786',
'390728319',
'391380417',
'391892437',
'391898822',
'391969458',
'392056354',
'392691440',
'392741237',
'393362439',
'393618335',
'393933643',
'393972880',
'394134415',
'394198246',
'394691273',
'394965834',
'395040116',
'395206469',
'397478504',
'397519976',
'397805698',
'397908278',
'397967894',
'398323964',
'398804534',
'398889493',
'398911461',
'399325026',
'399610898',
'399636836',
'399790625',
'400023172',
'400386751',
'400706198',
'400742763',
'400757894',
'400833968',
'400901518',
'401058615',
'401325303',
'401370499',
'401378948',
'401421268',
'401449749',
'401475983',
'401732433',
'401792122',
'401834981',
'401840442',
'401852496',
'401975727',
'402096838',
'402110373',
'402146013',
'402212872',
'402361299',
'402541593',
'402598528',
'402758866',
'402846695',
'403120363',
'403222391',
'403263080',
'403351190',
'403623820',
'403646532',
'404353609',
'407494814',
'407705185',
'407933381',
'408048064',
'408446706',
'408965788',
'409087822',
'409101706',
'409114113',
'409163565',
'409414299',
'410042501',
'410111611',
'410210686',
'410350102',
'410581243',
'410824437',
'411188246',
'411498785',
'411516768',
'411779036',
'411871585',
'412089435',
'412459562',
'413063488',
'413077793',
'413544693',
'413546821',
'413606773',
'413702440',
'413998048',
'414033597',
'414043240',
'414109850',
'414729046',
'414784843',
'417595881',
'417656121',
'417964871',
'417965522',
'418028593',
'418948659',
'419069224',
'419427760',
'419537584',
'419556600',
'419794839',
'419841960',
'420531907',
'420572877',
'420738254',
'420765216',
'420972267',
'421188525',
'421321001',
'421370222',
'421401712',
'421430844',
'421441866',
'421495060',
'421990052',
'422045138',
'422420273',
'422451799',
'422531400',
'422835413',
'423014844',
'423062827',
'423319128',
'423542224',
'423588672',
'423826726',
'423901289',
'423983956',
'424172310',
'424311975',
'424886513',
'428258297',
'428779219',
'428918171',
'429056146',
'429213655',
'429590425',
'429635113',
'429825425',
'430195156',
'431321959',
'431325497',
'431543925',
'431700996',
'431824564',
'431839422',
'431904689',
'432011591',
'432019743',
'432073864',
'432202026',
'432336196',
'432675320',
'432913630',
'433264140',
'433407699',
'433438751',
'433475977',
'433814936',
'433864055',
'434087029',
'434120283',
'434311668',
'434441838',
'434499315',
'434904173',
'434967725',
'434990297',
'435127998',
'435283452',
'435373568',
'437515232',
'437540669',
'437616659',
'437877368',
'438235541',
'438389231',
'438609984',
'438673816',
'438743858',
'439522350',
'439568346',
'439646266',
'439654591',
'440134278',
'440151900',
'440212090',
'440230225',
'440348456',
'440393734',
'440458677',
'440477685',
'440487296',
'440650885',
'440893592',
'441021698',
'441082609',
'441199551',
'441317989',
'441538964',
'441542016',
'441623923',
'441815966',
'441888344',
'442155032',
'442184743',
'442221404',
'442231262',
'442275988',
'442370912',
'442808127',
'442848990',
'442868469',
'443172788',
'443182175',
'443290143',
'443390935',
'443403191',
'443807698',
'444478713',
'444690226',
'444705560',
'444774103',
'444800130',
'444839997',
'444946057',
'444960686',
'445055130',
'445133986',
'445304868',
'445323959',
'447686635',
'447740069',
'447935594',
'448029561',
'448109363',
'448219204',
'448503482',
'448691188',
'448734301',
'448837880',
'449050970',
'449155621',
'449488238',
'449495118',
'449588250',
'449596733',
'449614270',
'449754001',
'449802263',
'449882133',
'450090683',
'450135058',
'450139571',
'450152517',
'450186259',
'450208681',
'450248208',
'450464425',
'450501804',
'450565007',
'450730569',
'450813365',
'451032007',
'451105209',
'451336507',
'451363782',
'451511950',
'451525224',
'451614788',
'451651699',
'451676613',
'451679831',
'451691406',
'451825921',
'451888416',
'451891923',
'451917108',
'451961924',
'452058142',
'452104078',
'452242456',
'452276041',
'452461874',
'452562697',
'452643471',
'452677867',
'452690829',
'452715733',
'452779689',
'452844723',
'452848880',
'453043689',
'453299299',
'453375024',
'453400863',
'453458333',
'453594863',
'453620106',
'453744252',
'453745093',
'453913147',
'453934309',
'454009044',
'454047945',
'477726590',
'477815948',
'477821169',
'477845986',
'478007099',
'478277239',
'478757826',
'479001745',
'479054843',
'479097669',
'479180895',
'479195687',
'479277006',
'479294084',
'479323230',
'479531584',
'479716938',
'479734337',
'479861619',
'479891145',
'479891244',
'480041011',
'480149962',
'480268218',
'480379262',
'480382126',
'480399740',
'480498419',
'480555929',
'480564103',
'480786334',
'480897651',
'480951177',
'481047512',
'481073666',
'481088771',
'481222578',
'481270429',
'481369312',
'481610442',
'481953891',
'482279155',
'482327350',
'482331840',
'482345212',
'482394715',
'482617057',
'482672359',
'482831815',
'482878139',
'483130845',
'483169827',
'483494803',
'483516969',
'483916490',
'484027321',
'484091202',
'484097787',
'484162458',
'484372768',
'484393996',
'484555172',
'484596887',
'484618442',
'484690375',
'484738729',
'484745492',
'484976121',
'484988167',
'487479610',
'487567067',
'487767550',
'487830465',
'487840373',
'487962805',
'488065418',
'488115353',
'488124926',
'488258351',
'488273467',
'488275157',
'488393513',
'488435280',
'488598541',
'488645748',
'488792615',
'489366120',
'489534271',
'489937698',
'490018504',
'490096229',
'490134228',
'490176583',
'490199668',
'490234010',
'490308418',
'490577004',
'490610524',
'490622891',
'490813029',
'490829603',
'490886041',
'490985256',
'491156576',
'491236451',
'491284006',
'491321634',
'491333290',
'491355558',
'491382982',
'491409116',
'491467890',
'491573069',
'491634945',
'491718227',
'491753612',
'491839122',
'491879961',
'491888954',
'491984852',
'492127733',
'492136783',
'492212287',
'492308069',
'492331269',
'492452966',
'492631486',
'492651658',
'492679006',
'492720529',
'492750179',
'492759139',
'492764956',
'492870142',
'492872353',
'492962584',
'493014278',
'493045819',
'493324289',
'493336473',
'493427009',
'493655781',
'493783674',
'493841696',
'493985717',
'494121825',
'494378607',
'494409089',
'494549371',
'494575780',
'494602055',
'494623614',
'494703994',
'494706773',
'495133589',
'495214967',
'495324519',
'495327066',
'495358152',
'495361867',
'495382517',
'497724591',
'497860502',
'497962985',
'497963306',
'498344027',
'498357011',
'498883651',
'498937333',
'498950948',
'499011393',
'499021053',
'499036937',
'499387405',
'499482875',
'499559532',
'499582930',
'499616944',
'499811677',
'499860922',
'500182449',
'500193958',
'500309638',
'500391214',
'500627054',
'500645536',
'500875810',
'501035455',
'501158844',
'501477822',
'501852438',
'501860084',
'502046642',
'502096969',
'502260854',
'502300239',
'502312002',
'502553373',
'502625080',
'502628019',
'503229627',
'503303877',
'503321168',
'503712481',
'503829277',
'503841900',
'504013814',
'504065244',
'504165044',
'504413865',
'504533670',
'504642927',
'504656364',
'504662131',
'504727900',
'504731357',
'504764135',
'504815234',
'504877770',
'505100842',
'505161497',
'505171355',
'505193722',
'505282616',
'507549756',
'507724425',
'507899219',
'507902708',
'507926715',
'508154648',
'508242864',
'508295953',
'508415619',
'508440831',
'508463361',
'508641214',
'508645736',
'508665205',
'508711090',
'508713674',
'508732781',
'508962222',
'509041604',
'509079166',
'509165429',
'509257739',
'509301784',
'542052246',
'552107930',
'572010841',
'572214948',
'602018046',
'604500439',
'612014639',
'668200785',
'672035854',
'691620504',
'692003890',
'702027681',
'704501527',
'712032804',
'712043256',
'721056646',
'722023728',
'732010780',
'738800986',
'779411701',
'781117494',
'784378432',
'784929234',
'784970600',
'785452434',
'786120212',
'788138733',
'872500889',
'915620736',
'937380186',
'945851079',
'962500880',
'997828728'
);
$nbRows=count($tabSiren);
//$nbRows=$iDbI->select( 'identite', 'SIREN, NIC, NOM, ADR_CP, ADR_LIBCOM, DCREN, CJ, APE_ENT', '1 AND ACTIF=1 AND SIEGE=1', false, MYSQL_ASSOC, true);
echo date('Y/m/d - H:i:s') ." - Il y a $nbRows entreprises à scorer...".EOL;
$k=0;
//while($entrep=$iDbI->fetch(MYSQL_ASSOC)) {
foreach ($tabSiren as $siren) {
$k++;
if ($k<$iDeb) continue;
//$siren=$entrep['SIREN'];
//$nic=$entrep['NIC'];
$nic=0;
//sleep(1);
$tabScore=@$iWs->getIndiScore($siren, $nic, false);
//print_r($tabScore);
//die();
if (@$tabScore['result']['DevraitPublier']) $pub='Oui';
else $pub='Non';
echo "$k;$siren".
';'. @$tabScore['result']['SituationJuridique'] .
';'. @$tabScore['result']['Actif'] .
';'. @$tabScore['result']['Nom'] .
';'. @$tabScore['result']['NafEtab'] .
';'. @$tabScore['result']['FJ'] .
';'. @$tabScore['result']['NbBilansScore'] .
';'. $pub .
';'. @$tabScore['result']['Indiscore'] .
';'. @$tabScore['result']['Indiscore20'] .
';'. @$tabScore['result']['TendanceIndiscore'] .
';'. @round($tabScore['result']['encours']/1000) .
';'. @round($tabScore['result']['ScoreDirigeance']/10) .
';'. @round($tabScore['result']['ScoreConfor']/10) .
';'. @$tabScore['result']['tabBilan'][0]['DATE_CLOTURE'] .
';'. @$tabScore['result']['tabBilan'][0]['DUREE_MOIS'] .
';'. @$tabScore['result']['tabBilan'][0]['MONNAIE'] .
';'. @$tabScore['result']['tabBilan'][0]['CONSOLIDE'] .
';'. @$tabScore['result']['tabBilan'][0]['MONNAIE_ORI'] .
';'. @$tabScore['result']['tabBilan'][0]['MONNAIE_LIV_UNITE'] .
';'. @$tabScore['result']['Bilans'][0]['EBE'],
';'. @$tabScore['result']['tabBilan'][0]['FL'] .
';'. @$tabScore['result']['tabBilan'][0]['GW'] .
';'. @$tabScore['result']['tabBilan'][0]['HN'] .
';'. @$tabScore['result']['tabBilan'][0]['BJ'] .
';'. @$tabScore['result']['tabBilan'][0]['BX'] .
';'. @$tabScore['result']['tabBilan'][0]['BZ'] .
';'. @$tabScore['result']['tabBilan'][0]['FL'] .
';'. @$tabScore['result']['tabBilan'][0]['BN'] .
';'. @$tabScore['result']['tabBilan'][0]['BP'] .
';'. @$tabScore['result']['tabBilan'][0]['BR'] .
';'. @$tabScore['result']['tabBilan'][0]['BT'] .
';'. @$tabScore['result']['tabBilan'][0]['CF'] .
';'. @$tabScore['result']['tabBilan'][0]['DL'] .
';'. @$tabScore['result']['tabBilan'][0]['EG'] .
';'. @$tabScore['result']['tabBilan'][0]['DX'] .
';'. @$tabScore['result']['scores']['Z'] .
';'. @$tabScore['result']['scores']['ConanH'] .
';'. @$tabScore['result']['scores']['Afdcc2'] .
';'. @$tabScore['result']['tabInfosNotations']['ProbabiliteDefaut'] . EOL;
// die();
/*
$tabInsert=array( 'siren' => $siren,
'nic' => $nic,
'dateClot' => $tabScore['result']['Bilans'][0]['Millesime'], // 20071231
'FraisPerso' => $tabScore['result']['Bilans'][0]['FraisPerso'], // 0.000374978604162
'CA' => $tabScore['result']['Bilans'][0]['CA'], // 13600776000
'EBE' => $tabScore['result']['Bilans'][0]['EBE'], // 681299000
'TxInvest' => $tabScore['result']['Bilans'][0]['TxInvest'], // 1.3119321726793
'TxEndett' => $tabScore['result']['Bilans'][0]['TxEndett'], // 80.787363987364
'DettesCT' => $tabScore['result']['Bilans'][0]['DettesCT'], // 1409599000
'FraisFi' => $tabScore['result']['Bilans'][0]['FraisFi'], // 0.53222698469558
'BFR' => $tabScore['result']['Bilans'][0]['BFR'], // 156636000
'FR' => $tabScore['result']['Bilans'][0]['FR'], // 179497000
'FondsPr' => $tabScore['result']['Bilans'][0]['FondsPr'], // 356125000
'DelaiCli' => $tabScore['result']['Bilans'][0]['DelaiCli'], // 24.301313572698
'DelaiFour' => $tabScore['result']['Bilans'][0]['DelaiFour'], // 22.385893771547
);
$iDb->insert('scores', $tabInsert);
//print_r($tabInsert);die();
if ($k%1000==0)
echo date('Y/m/d - H:i:s') ." - $k entreprises scorées ($siren)...".EOL;*/
}
die();
?>