diff --git a/scripts/calculScoreDate.php b/scripts/calculScoreDate.php new file mode 100644 index 00000000..ea817dfc --- /dev/null +++ b/scripts/calculScoreDate.php @@ -0,0 +1,149 @@ +getOptions()); +$db = Zend_Db::factory($c->profil->db->metier); +Zend_Db_Table::setDefaultAdapter($db); + +require_once APPLICATION_PATH.'/configs/config.php'; +require_once 'framework/fwk.php'; +require_once 'framework/common/chiffres.php'; +require_once 'framework/common/dates.php'; +require_once 'framework/mail/sendMail.php'; +require_once 'Metier/partenaires/classMLiens2.php'; +require_once 'Metier/partenaires/classMBanques.php'; +require_once 'Metier/insee/classMInsee.php'; + + +$fp = fopen('retour-'.date('YmdHis').'.csv', 'w'); +$delimiter = ','; +$fileHeader = array( + 'siren', + 'dateCalc', + 'SituationJuridique', + 'Indiscore', + 'Indiscore20', + 'ScoreSolvabilite', + 'ScoreDirigeance', + 'ScoreConfor', + 'encours', +); +fputcsv($fp, $fileHeader, $delimiter, '"'); + +foreach ($companies as $item) +{ + // --- Date de création de l'entreprise + $dateCreaEnSet = null; + $dateReal = new Zend_Date(); + // DCREN => insee.identite + $sql = $db->select()->from('identite', array('DCREN'), 'insee') + ->where('siren=?', $item)->order('SIEGE DESC')->order('ACTIF DESC')->limit(1); + $result = $db->fetchRow($sql, null, Zend_Db::FETCH_OBJ); + if ($result !== null) { + if ($dateReal->isDate($result->DCREN, 'yyyyMMdd')) { + $dateReal->set($result->DCREN, 'yyyyMMdd') ; + $dateCreaEnSet = 1; + } + } + + // DateImma + if ($dateCreaEn === null) { + $sql = $db->select()->from('rncs_entrep', array('dateImma'), 'jo') + ->where('siren=?', $item)->limit(1); + $result = $db->fetchRow($sql, null, Zend_Db::FETCH_OBJ); + if ($result !== null) { + if ($dateReal->isDate($result->dateImma, 'yyyy-MM-dd')) { + $dateReal->set($result->dateImma, 'yyyyMMdd') ; + $dateCreaEnSet = 1; + } + } + } + + if ($dateCreaEnSet === null) { + continue; + } + + // --- Date + $dateStop = new Zend_Date($dateStopIn, 'yyyy-MM-dd'); + $dateStart = new Zend_Date($dateStartIn, 'yyyy-MM-dd'); + + echo $item.' - '.$dateStart->toString('yyyy-MM-dd').' '.$dateStop->toString('yyyy-MM-dd')."\n"; + $difference = $dateStop->sub($dateStart); + $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); + $measure->convertTo(Zend_Measure_Time::MONTH); + $nbMonth = $measure->getValue(0) + 1; + + // --- Score + $dateCalcul = $dateStart; + for($i=0; $i<$nbMonth; $i++) { + $line = array(); + $line['siren'] = $item; + $line['dateCalc'] = $dateCalcul->toString('yyyy-MM-dd'); + echo "\t".$dateCalcul->toString('yyyy-MM-dd')."\n"; + if ($dateCalcul->compare($dateReal) == -1) { + echo "Inconnue à cette date\n"; + } else { + $score = new SdMetier_Scoring_Base(); + $score->setEvenLimit($dateCalcul->toString('yyyyMMdd')); + $result = $score->calculIndiScore($item, '', false, 0); + $line['DateCreaEn'] = $result['DateCreaEn']; + $line['Capital'] = $result['Capital']; + $line['SituationJuridique'] = $result['SituationJuridique']; + $line['Indiscore'] = $result['Indiscore']; + $line['Indiscore20'] = $result['Indiscore20']; + $line['ScoreSolvabilite'] = $result['ScoreSolvabilite']; + $line['ScoreDirigeance'] = $result['ScoreDirigeance']; + $line['ScoreConfor'] = $result['ScoreConfor']; + $line['encours'] = $result['encours']; + } + // Ecrire ligne CSV + $row = array(); + foreach ($fileHeader as $col) { + if (array_key_exists($col, $line)) { + $row[] = $line[$col]; + } else { + $row[] = ''; + } + } + fputcsv($fp, $row, $delimiter, '"'); + + // date +1 + $dateCalcul->addMonth(1); + } +} + +fclose($fp); \ No newline at end of file