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'; $fp = fopen($file.'-'.date('YmdHis').'.csv', 'w'); $delimiter = ','; $fileHeader = array( 'siren', 'dateCalc', 'DateCreaEn', 'Capital', 'SituationJuridique', 'Indiscore', 'Indiscore20', 'ScoreSolvabilite', 'ScoreDirigeance', 'ScoreConfor', 'encours', ); fputcsv($fp, $fileHeader, $delimiter, '"'); $cpt = 1; 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 ($dateCreaEnSet === 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 date('Y-m-d H:i:s').' - '.$cpt.' - '.$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 date('Y-m-d H:i:s').' - '.$cpt."\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); } $cpt++; } fclose($fp);