"Aide.", 'ratios' => "Génére la class des ratios (classMRatios.php)", 'type-s' => "Choix du type d'indiScore : score ou valo", 'formules-s' => "Génére le code Formules{type}{versions}.php", 'comments-s' => "Génére le cache des Comments{type}{versions}.php", 'niveau=s' => "Niveau de commentaire", 'tabcache' => "Tab in cache", )); $opts->parse(); } catch (Zend_Console_Getopt_Exception $e) { $displayUsage = true; } // --- Aide / Options if (count($opts->getOptions())==0 || isset($opts->help)) { $displayUsage = true; } // --- Usage if ($displayUsage) { echo "\nRatios et Formules\n\n"; echo $opts->getUsageMessage(); exit; } $c = new Zend_Config($application->getOptions()); Zend_Registry::set('config', $c); // Database $config = new \Doctrine\DBAL\Configuration(); $connectionParams = array( 'dbname' => $c->profil->db->metier->params->dbname, 'user' => $c->profil->db->metier->params->username, 'password' => $c->profil->db->metier->params->password, 'host' => $c->profil->db->metier->params->host, 'charset' => 'utf8', 'driver' => 'pdo_mysql', ); try { $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); } catch (\Doctrine\DBAL\DBALException $e) { echo "Connection Database impossible.\n"; exit; } // Fichier MRatios if (isset($opts->ratios)) { $configFile = APPLICATION_PATH.'/../library/Metier/Scores/MRatios.php'; $fp = fopen($configFile, 'w'); fwrite($fp, ''R[801]', 'R01b'=>'Rh[801]', 'R01c'=>'Rs[801]', 'R02a'=>'R[802]', 'R02b'=>'Rh[802]', 'R02c'=>'Rs[802]', 'R02d'=>'Rq[802]', 'R02e'=>'Rt[802]', 'R03a'=>'R[803]', 'R03b'=>'Rh[803]', 'R03c'=>'Rs[803]', 'R03d'=>'Rq[803]', 'R03e'=>'Rt[803]', 'R04a'=>'R[804]', 'R04b'=>'Rh[804]', 'R04c'=>'Rs[804]', 'R04d'=>'Rq[804]', 'R04e'=>'Rt[804]', 'R05a'=>'R[805]', 'R05b'=>'Rh[805]', 'R05c'=>'Rs[805]', 'R06a'=>'R[806]', 'R06b'=>'Rh[806]', 'R06c'=>'Rs[806]', 'R06d'=>'Rq[806]', 'R06e'=>'Rt[806]', 'R07a'=>'R[807]', 'R07b'=>'Rh[807]', 'R07c'=>'Rs[807]', 'R07d'=>'Rq[807]', 'R07e'=>'Rt[807]', 'R08a'=>'R[808]', 'R08b'=>'Rh[808]', 'R08c'=>'Rs[808]', 'R08d'=>'Rq[808]', 'R08e'=>'Rt[808]', 'R09a'=>'R[809]', 'R09b'=>'Rh[809]', 'R09c'=>'Rs[809]', 'R09d'=>'Rq[809]', 'R09e'=>'Rt[809]', 'R10a'=>'R[810]', 'R10b'=>'Rh[810]', 'R10c'=>'Rs[810]', 'R10d'=>'Rq[810]', 'R10e'=>'Rt[810]', 'R11a'=>'R[811]', 'R11b'=>'Rh[811]', 'R11c'=>'Rs[811]', 'R12a'=>'R[812]', 'R12b'=>'Rh[812]', 'R12c'=>'Rs[812]', 'R13a'=>'R[813]', 'R13b'=>'Rh[813]', 'R13c'=>'Rs[813]', 'R13d'=>'Rq[813]', 'R13e'=>'Rt[813]', 'R14a'=>'R[814]', 'R14b'=>'Rh[814]', 'R14c'=>'Rs[814]', 'R14d'=>'Rq[814]', 'R14e'=>'Rt[814]', 'R15a'=>'R[815]', 'R15b'=>'Rh[815]', 'R15c'=>'Rs[815]', 'R15d'=>'Rq[815]', 'R15e'=>'Rt[815]', 'R16a'=>'R[816]', 'R16b'=>'Rh[816]', 'R16c'=>'Rs[816]', 'R16d'=>'Rq[816]', 'R16e'=>'Rt[816]', 'R17a'=>'R[817]', 'R17b'=>'Rh[817]', 'R17c'=>'Rs[817]', 'R18a'=>'R[818]', 'R18b'=>'Rh[818]', 'R18c'=>'Rs[818]', 'R18d'=>'Rq[818]', 'R18e'=>'Rt[818]', 'R19a'=>'R[819]', 'R19b'=>'Rh[819]', 'R19c'=>'Rs[819]', 'R19d'=>'Rq[819]', 'R19e'=>'Rt[819]', 'R20a'=>'R[820]', 'R20b'=>'Rh[820]', 'R20c'=>'Rs[820]', 'R20d'=>'Rq[820]', 'R20e'=>'Rt[820]', 'R21a'=>'R[821]', 'R21b'=>'Rh[821]', 'R21c'=>'Rs[821]', 'R21d'=>'Rq[821]', 'R21e'=>'Rt[821]', 'R22a'=>'R[822]', 'R22b'=>'Rh[822]', 'R22c'=>'Rs[822]', 'R23a'=>'R[823]', 'R23b'=>'Rh[823]', 'R23c'=>'Rs[823]', 'R24a'=>'R[824]', 'R24b'=>'Rh[824]', 'R24c'=>'Rs[824]', 'R25a'=>'R[825]', 'R25b'=>'Rh[825]', 'R25c'=>'Rs[825]', 'R26a'=>'R[826]', 'R26b'=>'Rh[826]', 'R26c'=>'Rs[826]', 'R26d'=>'Rq[826]', 'R26e'=>'Rt[826]', 'R27a'=>'R[827]', 'R27b'=>'Rh[827]', 'R27c'=>'Rs[827]', 'R27d'=>'Rq[827]', 'R27e'=>'Rt[827]', 'R28a'=>'R[828]', 'R28b'=>'Rh[828]', 'R28c'=>'Rs[828]', 'R28d'=>'Rq[828]', 'R28e'=>'Rt[828]', 'R29a'=>'R[829]', 'R29b'=>'Rh[829]', 'R29c'=>'Rs[829]', 'R29d'=>'Rq[829]', 'R29e'=>'Rt[829]', 'R30a'=>'R[830]', 'R30b'=>'Rh[830]', 'R30c'=>'Rs[830]', 'R30d'=>'Rq[830]', 'R30e'=>'Rt[830]', 'R31a'=>'R[843]', 'R31b'=>'Rh[843]', 'R31c'=>'Rs[843]', 'R31d'=>'Rq[843]', 'R31e'=>'Rt[843]', 'R32a'=>'R[831]', 'R32b'=>'Rh[831]', 'R32c'=>'Rs[831]', 'R33a'=>'R[832]', 'R33b'=>'Rh[832]', 'R33c'=>'Rs[832]', 'R33d'=>'R[845]', 'R33e'=>'Rh[845]', 'R33f'=>'Rs[845]', 'R34a'=>'R[833]', 'R34b'=>'Rh[833]', 'R34c'=>'Rs[833]', 'R34d'=>'R[846]', 'R34e'=>'Rh[846]', 'R34f'=>'Rs[846]', 'R35a'=>'R[834]', 'R35b'=>'Rh[834]', 'R35c'=>'Rs[834]', 'R35d'=>'R[847]', 'R35e'=>'Rh[847]', 'R35f'=>'Rs[847]', 'R36a'=>'R[835]', 'R36b'=>'Rh[835]', 'R36c'=>'Rs[835]', 'R36d'=>'R[849]', 'R36e'=>'Rh[849]', 'R36f'=>'Rs[849]', 'R37a'=>'R[844]', 'R37b'=>'Rh[844]', 'R37c'=>'Rs[844]', 'R37d'=>'R[848]', 'R37e'=>'Rh[848]', 'R37f'=>'Rs[848]', 'R38a'=>'R[836]', 'R38b'=>'Rh[836]', 'R38c'=>'Rs[836]', 'R38d'=>'Rq[836]', 'R38e'=>'Rt[836]', 'R39a'=>'R[837]', 'R39b'=>'Rh[837]', 'R39c'=>'Rs[837]', 'R39d'=>'Rq[837]', 'R39e'=>'Rt[837]', 'R40a'=>'R[838]', 'R40b'=>'Rh[838]', 'R40c'=>'Rs[838]', 'R40d'=>'Rq[838]', 'R40e'=>'Rt[838]', 'R41a'=>'R[842]', 'R41b'=>'Rh[842]', 'R41c'=>'Rs[842]', 'R41d'=>'Rq[842]', 'R41e'=>'Rt[842]', 'R42a'=>'R[839]', 'R42b'=>'Rh[839]', 'R42c'=>'Rs[839]', 'R42d'=>'Rq[839]', 'R42e'=>'Rt[839]', 'R43a'=>'R[840]', 'R43b'=>'Rh[840]', 'R43c'=>'Rs[840]', 'R43d'=>'Rq[840]', 'R43e'=>'Rt[840]', 'R44a'=>'R[841]', 'R44b'=>'Rh[841]', 'R44c'=>'Rs[841]', ); public function __construct(\$db = null) { if ( \$db === null ) { \$this->iDb = new Metier_Util_Db(); } else { \$this->iDb = \$db; } } /** * Conversion des zones pour les collectivités * @param unknown \$codeR * @param unknown \$zonesDB * @return array */ public function convertZones(\$codeR, \$zonesDB) { foreach(\$this->tabZones2Ratios as \$oldR=>\$newR) { if (preg_match('/(\D+)\[(\d+)\]/Uis', \$newR, \$matches) && \$matches[1]==\$codeR) { \$iRatio=\$matches[2]; if (\$codeR=='R') \$ret[\$iRatio]=\$zonesDB[\$oldR]*1000; else \$ret[\$iRatio]=\$zonesDB[\$oldR]; } } return \$ret; } /** * Donne le taux d'inflation pour une année donnée * @param unknown \$annee * @return unknown */ public function getInflation(\$annee) { \$tabInfla = include __DIR__ . '/Data/Infla.php'; if ( isset(\$tabInfla[\$annee]) ) { return \$tabInfla[\$annee]; } } /** * Donne le taux de rendement des actions pour une année donnée * @param unknown \$annee * @return unknown */ public function getTxRendement(\$annee) { \$tabTxRendObli = include __DIR__ . '/Data/RendObli.php'; if ( isset(\$tabTxRendObli[\$annee]) ) { return \$tabTxRendObli[\$annee]; } } /** * Taux de tva * @param string \$date AAAAMM * @return double */ public function getTxTva(\$date) { \$tabTxTva = include __DIR__ . '/Data/Tva.php'; foreach (\$tabTxTva as \$ym => \$v) { if (\$ym > \$date) { break; } \$tva = \$v; } return \$tva; } /** * Définit la tranche d'effectif * @param int \$value */ public function setTrancheEffectif(\$value) { \$this->efftr = \$value; } /** * Calcul les ratios * @param array \$bilans * Format des bilans à envoyer * * Les bilans doivent être envoyés trier * @return array */ public function calcul(\$bilans) { \$numBil = 0; foreach (\$bilans as \$k => \$p) { \$millesime = \$p['DATE_CLOTURE']; \$tva = \$this->getTxTva(substr(\$millesime,0,6)); // --- Calcul " . "\n"); fwrite($fp, "\t\t\t" . "\$nm=\$p['DUREE_MOIS'];" ."\n"); fwrite($fp, "\t\t\t" . "\$nmp=\$p['DUREE_MOIS_PRE'];" ."\n"); fwrite($fp, "\t\t\t" . "\$R=array();" ."\n"); $stmt = $conn->executeQuery("SELECT id, libelle, formule, unite, commentaires, borneMin, borneMax, calcul, deleted FROM jo.ratios_formules WHERE deleted=0"); $tabMoy = array(); while ($formule = $stmt->fetch(\PDO::FETCH_ASSOC)) { $id = intval($formule['id']); $libelle = $formule['libelle']; $unite = $formule['unite']; /** Ratios avec formules à calculer **/ if ($formule['calcul']) { $formuleStr = $formule['formule']; if (preg_match("/^MOY\(R\[(.*)\],(.*)\)/Ui", $formuleStr, $matches)) { $tabMoy[$id]=array( 'ratio'=>$matches[1]*1, 'nbExo'=>$matches[2]*1, ); continue; } // Gestion des variables minuscules de 1 à 8 caractères alphanumériques $formule1 = preg_replace('/(tva|efftr|nm)/','\$this->$1', $formuleStr); $formule1 = preg_replace('/([a-z]{1,8})/','\$$1', $formuleStr); // Gestion des postes du BILAN AX, BX, YP, FL1, etc... $formule1 = preg_replace('/\b([A-Z]{2,2}[1-9]{0,1})\b/','\$p[\'$1\']', $formule1); // Gestion des ratios précédent $formule1 = preg_replace_callback('/\bR\[(.*)\]/U', function($match) { return '$R['.intval($match[1]).']'; }, $formule1); // Gestion des valeurs Absolues $formule1 = preg_replace('/\|(.*)\|/U', 'abs($1)', $formule1); // Gestion de l'inflation pour l'année du bilan $formule1 = preg_replace('/\INFLATION/U', '$this->getInflation(substr($millesime,4))', $formule1); // Ecriture de la formule $formule1 = "\$R[$id]=".$formule1.';'; /** fonction ou **/ if (preg_match('/ \$ou (.*)/', $formule1, $matches)) { $formule1 = preg_replace('/ \$ou (.*)/',';', $formule1); $alternative = $matches[1]; $formule1.= "\t" . "if (\$R[$id]==0) { \$R[$id] = $alternative }"; } /** Bornage des résultats en cas de dépassement **/ if (preg_match('/;BORN\((.*)\)/U', $formule1, $matches)) { $formule1 = preg_replace('/(;BORN\(.*\))/U','', $formule1); $tabBornes = explode(':', $matches[1]); if (trim($tabBornes[0])<>'') { $bMin = trim($tabBornes[0])*1; $formule1.= "\t" . "if (\$R[$id]<$bMin) { \$R[$id] = $bMin; }"; } if (isset($tabBornes[1]) && trim(@$tabBornes[1])<>'') { $bMax =trim($tabBornes[1])*1; $formule1.= "\t" . "if (\$R[$id]>$bMax) { \$R[$id] = $bMax; }"; } } /** Bornage des résultats en cas de dépassement **/ if (preg_match('/;LIM\((.*)\)/U', $formule1, $matches)) { $formule1 = preg_replace('/(;LIM\(.*\))/U','', $formule1); $bMax = trim($matches[1])*1; $formule1.= "\t" . "if (\$R[$id]>$bMax) { \$R[$id] = $bMax; }"; } $formule2 = $formule1; fwrite($fp, "\t\t\t" . $formule2 . "\n"); fwrite($fp, "\t\t\t" . "if (!isset(\$R[".$id."])) { \$R[".$id."] = 'NS'; }" . "\n\n"); } } fwrite($fp, "\n"); fwrite($fp, "\t\t\t" . '$tabRatios[$numBil]=$R;'."\n"); fwrite($fp, "\t\t\t" . '$numBil++;'."\n"); fwrite($fp, "\t\t" . "}" ."\n\n"); foreach($tabMoy as $iRatio=>$tMoy) { $irMoy=$tMoy['ratio']; $nbExo=$tMoy['nbExo']; fwrite($fp, "\t\t" . "for(\$i=0; \$i<\$numBil; \$i++) {" . "\n"); fwrite($fp, "\t\t\t" . "\$tabRatios[\$i][".$iRatio."]=(\$tabRatios[\$i][".$irMoy."]"); for($i=1; $i<$nbExo; $i++) { fwrite($fp, '+$tabRatios[$i+'.$i.']['.$irMoy.']'); } fwrite($fp, ")/".$nbExo.";" . "\n"); fwrite($fp, "\t\t" . "}" . "\n\n"); } fwrite($fp, "\t\t" . "return \$tabRatios;" . "\n"); fwrite($fp, "\t" . "}" . "\n"); fwrite($fp, "}" . "\n"); fclose ($fp); $strOutput=exec('php -l '.$configFile, $output); if (preg_match('/^No syntax errors detected in /', $strOutput)) { } else { print_r($output); return false; } return true; } // --- Formules if (isset($opts->formules)) { if ( isset($opts->type) && in_array($opts->type, array('score', 'valo')) ) { $type = $opts->type; } else { $type = 'score'; } $cycle = 2; $version = $opts->formules; // Select the right table in database in function of type switch ($type) { case 'score': $file = APPLICATION_PATH.'/../library/Metier/Scores/Formule/Score_'.$version.'.php'; $tableFormu = 'jo.scores_formules_'.$version; $tableComment = 'jo.scores_commentaires_'.$version; break; case 'valo': $file = APPLICATION_PATH.'/../library/Metier/Scores/Formule/Valo_'.$version.'.php'; $tableFormu = 'jo.valo_formules_'.$version; $tableComment = 'jo.valo_commentaires_'.$version; break; } // Read comments $stmt = $conn->executeQuery("SELECT code, langue, cycle, ligne, commentaire, tri, deleted FROM $tableComment WHERE deleted=0 AND cycle=$cycle AND ligne NOT LIKE '%*%' AND commentaire NOT LIKE '.*%' ORDER BY langue ASC, cycle ASC, code ASC, ligne ASC"); $tabCommentaires = $tabTri = $tabTriAff = array(); while ($commentaire = $stmt->fetch(\PDO::FETCH_ASSOC)) { $id = $commentaire['code']*1; $ligne = $commentaire['ligne']*1; $tabCommentaires[$id][$ligne] = str_replace('"','\"',$commentaire['commentaire']); if ($commentaire['tri']) { //$tabTri[$id] = $commentaire['tri']; $tabTriAff[$id] = ($commentaire['tri'].'.'.(10000000+(1*$commentaire['code'])))*1; } } // Read formulas $stmt = $conn->executeQuery("SELECT code, ligne, remarque, operande, ope1, operation, valeur FROM $tableFormu WHERE deleted=0 AND code>1 AND ligne NOT LIKE '%*%' ORDER BY code ASC, ligne ASC"); $idPre = $strFormule = false; $debugFormule = ''; $fp = fopen($file,'w'); fwrite($fp,'fetch(\PDO::FETCH_ASSOC)) { $id = $formule['code']*1; if ($idPre != $id && $idPre != false) { $debugFormule.= $strFormule.') { $C['.$idPre."]=true; $strAction } \t"; $strFormule = preg_replace('/\|([A-Z0-9\. \$\[\]]{1,12})\|/Ui', 'abs($1)', $strFormule); $strFormule = preg_replace('/\$R\[0+/', '$R[', $strFormule); $strFormule = preg_replace('/\$Ra\[0+/', '$Ra[', $strFormule); $strFormule = preg_replace('/\$Rap\[0+/', '$Rap[', $strFormule); $strFormule = preg_replace('/\$Rp\[0+/', '$Rp[', $strFormule); $strFormule = preg_replace('/\$Rs\[0+/', '$Rs[', $strFormule); $strFormule = preg_replace('/\$Rsp\[0+/', '$Rsp[', $strFormule); $strFormule = preg_replace('/\$Revol\[0+/', '$Revol[', $strFormule); $strFormule = preg_replace('/\$Revolp\[0+/', '$Revolp[', $strFormule); $strFormule = preg_replace('/\$Revols\[0+/', '$Revols[', $strFormule); $strFormule = preg_replace('/\$Rdiff\[0+/', '$Rdiff[', $strFormule); for ($j=2; $j<5; $j++) { $strFormule = preg_replace('/\$Rp'.$j.'\[0+/', '$Rp'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Rs'.$j.'\[0+/', '$Rs'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Rsp'.$j.'\[0+/', '$Rsp'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Revol'.$j.'\[0+/', '$Revol'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Revolp'.$j.'\[0+/', '$Revolp'.$j.'[', $strFormule); } $strAction = preg_replace('/\|([A-Z0-9\. \$\[\]]{1,12})\|/Ui', 'abs($1)', $strAction); $strAction = preg_replace('/\$R\[0+/', '$R[', $strAction); $strAction = preg_replace('/\$Ra\[0+/', '$Ra[', $strAction); $strAction = preg_replace('/\$Rap\[0+/', '$Rap[', $strAction); $strAction = preg_replace('/\$Rp\[0+/', '$Rp[', $strAction); $strAction = preg_replace('/\$Rs\[0+/', '$Rs[', $strAction); $strAction = preg_replace('/\$Rsp\[0+/', '$Rsp[', $strAction); $strAction = preg_replace('/\$Revol\[0+/', '$Revol[', $strAction); $strAction = preg_replace('/\$Revolp\[0+/', '$Revolp[', $strAction); $strAction = preg_replace('/\$Rdiff\[0+/', '$Rdiff[', $strAction); fwrite($fp, $remarque."\n"); // Remplace "$" par "$this->" fwrite($fp, str_replace('$', '$this->', $strFormule.') { $C['.$idPre."]=true; $strAction } ")."\n"); eval( $strFormule.') { $C['.$idPre."]=true; $strAction } " ); $debugFormule.= '$C['.$idPre.']='.$C[$idPre]."\r\n"; $remarque = "// $id-".$formule['ligne'].' : '.$formule['remarque']; $strAction = ''; } elseif (!$idPre) { $remarque = "// $id-".$formule['ligne']; } else { $remarque.= ' '.strtr($formule['remarque'],array("\r"=>' ',"\n"=>' ')); } $ligne = $formule['ligne']*1; $operande = trim(strtr(strtoupper($formule['operande']),array(':'=>''))); $ope1 = trim($formule['ope1']); // PROJECTAUX PROJECCOEF PROJEC if (preg_match("/(PROJECTAUX|PROJECCOEF|PROJEC)\((.*)\)/Ui", $ope1, $matches)) { $ope1 = $matches[1].'($'.preg_replace('/R\[0+/', 'regR[', str_replace('+', '', $matches[2])).')'; } // Gestion du mot clef LONG elseif (preg_match('/^LONG\(([A-Z0-9\_]{1,30})\)$/i', $ope1, $matches)) { $ope1 = preg_replace('/^LONG\(([A-Z0-9\_]{1,30})\)$/i','strlen(\$$1)', $ope1); } // Gestion du substr else { $ope1 = preg_replace('/([A-Z0-9\_]{1,30})\((.*)\)$/i','substr(\$$1,$2)', $ope1); } $operation = trim($formule['operation']); if ($operation=='=') $operation='=='; $valeur = trim(strtr($formule['valeur'], array('"'=>"'"))); if (preg_match("/^MOY\(R(.*),(.*)\)/Ui", $valeur, $matches)) { $valeur = '( (R'.$matches[1]; for($iMoy=0; $iMoy<$matches[2]; $iMoy++) { if ($iMoy == 1) { $valeur.= '+Rp'.$matches[1]; } else { $valeur.= '+Rp'.$iMoy.$matches[1]; } } $valeur.= ')/'.$matches[2].')'; } else { $valeur = preg_replace('/([A-Z\_]{1,30})\((.*)\)$/i','substr(\$$1,$2)', $valeur); } if ( !empty($valeur) && substr($valeur,0,1) != "'" && !preg_match('/\(.*;.*\)/', $valeur) && substr($valeur,0,6) != 'substr' && !in_array($valeur, array('vrai', 'faux')) ) { //file_put_contents('test.log', $valeur, FILE_APPEND); //$valeur = preg_replace('/([A-Z][A-Za-z0-9\_]{1,29}|[A-Za-z0-9]{1,30}\[[0-9]+\])/', '\$$1' , $valeur); $valeur = preg_replace('/([A-Z][A-Za-z0-9\_]{0,29}|[A-Za-z0-9]{1,30}\[[0-9]+\])/', '\$$1' , $valeur); //file_put_contents('test.log', " = ".$valeur."\n", FILE_APPEND); } if (preg_match("/^substr|^projec|^strlen|^\||^'/i", $ope1)) { $ope1deb = ''; $ope1 = strtr($ope1, array( '|R[' => '|$R[', '|Rp[' => '|$Rp[', '|Rp2[' => '|$Rp2[', '|Rp3[' => '|$Rp3[', '|Rs[' => '|$Rs[', '|Rsp[' => '|$Rsp[', '|Revol[' => '|$Revol[', '|Revolp[' => '|$Revolp[', '|Revols[' => '|$Revols[', '|Rdiff[' => '|$Rdiff[', )); } else { $ope1deb = '$'; $ope1 = strtr($ope1, array( '/R[' => '/$R[', '/Rp[' => '/$Rp[', '/Rp2[' => '/$Rp2[', '/Rp3[' => '/$Rp3[', '/Rs[' => '/$Rs[', '/Rsp[' => '/$Rsp[', '/Revol[' => '/$Revol[', '/Revolp[' => '/$Revolp[', '/Revols[' => '/$Revols[', '/Rdiff[' => '/$Rdiff[', )); } //(C[5000100]àC[5000998]) if (preg_match('/^C\[(.*)\]àC\[(.*)\]$/', $ope1, $matches)) { // On veut savoir si des commentaires Cxx à Cyy sont chargés $tabTmp4 = array(); foreach ($tabTri as $idxC=>$t) { if ($idxC>=$matches[1] && $idxC<=$matches[2]) $tabTmp4[]=' isset($C['.$idxC.']) '; } $tmpFormule='true'; if (count($tabTmp4)>0) $tmpFormule=' ('.implode(' || ', $tabTmp4).') '; } elseif (preg_match_all('/^\((C\[(.*)\];?)+\)$/', $ope1, $matches)) { $tabTmp5=explode(';', $matches[1][0]);// C[3255000];C[3260000];C[3265000] $tabTmp4=array(); foreach ($tabTmp5 as $t) $tabTmp4[]=' isset($'.$t.') '; $tmpFormule='true'; if (count($tabTmp4)>0 && preg_match('/NON/i',$operande)) $tmpFormule=' ('.implode(' && ', $tabTmp4).') '; elseif (count($tabTmp4)>0) $tmpFormule=' ('.implode(' || ', $tabTmp4).') '; } elseif (($operation=='==' || $operation=='<>') && preg_match('/\(.*;.*\)/', $valeur)) { /** Gestion du point-virgule (correspond à un IN dans WHERE sql **/ $tabTmp3=explode(';', $valeur); $tabTmp4=array(); foreach ($tabTmp3 as $i3=>$svaleur) $tabTmp4[]=$ope1deb.$ope1.$operation.strtr($svaleur,array('('=>'', ')'=>'', ','=>'.')); if ($operation=='==') $tmpFormule=' ('.implode(' || ', $tabTmp4).') '; else $tmpFormule=implode(' && ', $tabTmp4); } elseif ($operande=='ET' && preg_match('/\(.*;.*\)/', $ope1)) { /** Gestion du point-virgule (correspond à un IN dans WHERE sql **/ $tabTmp3=explode(';', $ope1); $tabTmp4=array(); foreach ($tabTmp3 as $i3=>$ope1val) $tabTmp4[]=$ope1deb.strtr($ope1val,array('('=>'', ')'=>'', ','=>'.')); $tmpFormule=' ('.implode(' && ', $tabTmp4).') '; } elseif (preg_match('/(.*)à(.*)/', $valeur, $matches)) { /** Gestion du 'à' (correspond à min < xxx < max **/ $tmpFormule=' ('.$ope1deb.$ope1.' >= '.$matches[1].' && '.$ope1deb.$ope1.' <= '.$matches[2].') '; } else { if (!preg_match("/^substr/", $valeur)) { $valeur = strtr($valeur,array(','=>'.')); } if ($operation=='' && $valeur=='') { $tmpFormule=$ope1deb.$ope1; } elseif ($operation<>'' && $valeur=='') { $tmpFormule=$ope1deb.$ope1.$operation."''"; } elseif (strtoupper($valeur)==strtolower($valeur) && $valeur<>'') { $tmpFormule=$ope1deb.$ope1.$operation.$valeur; } elseif (strtolower($valeur)=='vrai') { $tmpFormule=$ope1deb.$ope1.$operation.'true'; } elseif (strtolower($valeur)=='faux') { $tmpFormule=$ope1deb.$ope1.$operation.'false'; } elseif (strtolower($valeur)=='nmp') { $tmpFormule=$ope1deb.$ope1.$operation.'$nmp'; } else { $tmpFormule=$ope1deb.$ope1.$operation.$valeur; } } $strParentDeb=$strParentFin=''; if (preg_match_all('/(\()/',$operande,$matches)) { $strParentDeb=implode(' ', $matches[1]); $operande=trim(strtr($operande,array('('=>''))); } elseif (preg_match_all('/(\))/',$operande,$matches)) { $strParentFin=implode(' ', $matches[1]); $operande=trim(strtr($operande,array(')'=>''))); } switch ($operande) { case 'SI': $strFormule= "if ( $strParentDeb $tmpFormule $strParentFin"; break; case 'SI NON': $strFormule= "if ( $strParentDeb !($tmpFormule) $strParentFin"; break; case 'ET': $strFormule.= " && $strParentDeb $tmpFormule $strParentFin"; break; case 'ET NON': $strFormule.= " && $strParentDeb !($tmpFormule) $strParentFin"; break; case 'OU': $strFormule.= " || $strParentDeb $tmpFormule $strParentFin"; break; case 'OU NON': $strFormule.= " || $strParentDeb !($tmpFormule) $strParentFin"; break; case 'ACTION': $strAction.= str_replace('==','=', " $tmpFormule; "); break; case 'ECHANGE': $ECHANGE[] = $tmpFormule; break; default: echo 'Indiscore '.$id.' OPERANDE INCONNUE '.$operande."\n"; break; } $idPre = $id; //echo $strFormule."\n"; } // --- Gestion de la dernière ligne de commentaire $debugFormule.= $strFormule.') ) $C['.$idPre.']=true;'."\t"; $strFormule = preg_replace('/\|([A-Z0-9\. \$\[\]]{1,12})\|/Ui', 'abs($1)', $strFormule); $strFormule = preg_replace('/\$R\[0+/', '$R[', $strFormule); $strFormule = preg_replace('/\$Ra\[0+/', '$Ra[', $strFormule); $strFormule = preg_replace('/\$Rap\[0+/', '$Rap[', $strFormule); $strFormule = preg_replace('/\$Rp\[0+/', '$Rp[', $strFormule); $strFormule = preg_replace('/\$Rs\[0+/', '$Rs[', $strFormule); $strFormule = preg_replace('/\$Rsp\[0+/', '$Rsp[', $strFormule); $strFormule = preg_replace('/\$Revol\[0+/', '$Revol[', $strFormule); $strFormule = preg_replace('/\$Revolp\[0+/', '$Revolp[', $strFormule); $strFormule = preg_replace('/\$Revols\[0+/', '$Revols[', $strFormule); $strFormule = preg_replace('/\$Rdiff\[0+/', '$Rdiff[', $strFormule); for ($j=2;$j<5;$j++) { $strFormule = preg_replace('/\$Rp'.$j.'\[0+/', '$Rp'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Rs'.$j.'\[0+/', '$Rs'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Rsp'.$j.'\[0+/', '$Rsp'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Revol'.$j.'\[0+/', '$Revol'.$j.'[', $strFormule); $strFormule = preg_replace('/\$Revolp'.$j.'\[0+/', '$Revolp'.$j.'[', $strFormule); } $strAction = preg_replace('/\|([A-Z0-9\. \$\[\]]{1,12})\|/Ui', 'abs($1)', $strAction); $strAction = preg_replace('/\$R\[0+/', '$R[', $strAction); $strAction = preg_replace('/\$Ra\[0+/', '$Ra[', $strAction); $strAction = preg_replace('/\$Rap\[0+/', '$Rap[', $strAction); $strAction = preg_replace('/\$Rp\[0+/', '$Rp[', $strAction); $strAction = preg_replace('/\$Rs\[0+/', '$Rs[', $strAction); $strAction = preg_replace('/\$Rsp\[0+/', '$Rsp[', $strAction); $strAction = preg_replace('/\$Revol\[0+/', '$Revol[', $strAction); $strAction = preg_replace('/\$Revolp\[0+/', '$Revolp[', $strAction); $strAction = preg_replace('/\$Rdiff\[0+/', '$Rdiff[', $strAction); eval ($strFormule.') $C['.$idPre.']=true;'); // Remplace "$" par "$this->" fwrite($fp, str_replace('$', '$this->', $strFormule.') $C['.$idPre.']=true;')."\n"); fwrite($fp, str_replace('$', '$this->', $strFormule.') $C['.$idPre.']=true;')."\n"); fwrite($fp, "\n".'$ECHANGE=\''.serialize($ECHANGE)."';"."\n"); fwrite($fp, "\n".'?>'."\n"); fclose($fp); $debugFormule.='$C['.$idPre.']='.$C[$idPre]."\r\n"; $strOutput=exec('php -l '.$file, $output); if (preg_match('/^No syntax errors detected in /', $strOutput)) { echo "Aucune erreur\n"; } else { echo "Erreur : $strOutput\n"; print_r($output); } } // --- Commentaires if ( isset($opts->comments) ) { if ( isset($opts->type) && in_array($opts->type, array('score', 'valo')) ) { $type = $opts->type; } else { $type = 'score'; } $cycle = 2; if (isset($opts->niveau)) { $cycle = $opts->niveau; } $version = $opts->comments; // Select the right table in database in function of type switch ($type) { case 'score': $tableComment = 'jo.scores_commentaires_'.$version; break; case 'valo': $tableComment = 'jo.valo_commentaires_'.$version; break; } $path = APPLICATION_PATH.'/../library/Metier/Scores/Comment'; // Read comments text $stmt = $conn->executeQuery("SELECT code, langue, cycle, ligne, commentaire, tri, deleted FROM $tableComment WHERE deleted=0 AND cycle=$cycle AND ligne NOT LIKE '%*%' AND commentaire NOT LIKE '.*%' ORDER BY langue ASC, cycle ASC, code ASC, ligne ASC"); $tabCommentaires = $tabTri = $tabTriAff = array(); while ($commentaire = $stmt->fetch(\PDO::FETCH_ASSOC)) { $id = $commentaire['code']*1; $ligne = $commentaire['ligne']*1; $tabCommentaires[$id][$ligne] = str_replace('"','\"',$commentaire['commentaire']); if ($commentaire['tri']) { //$tabTri[$id] = $commentaire['tri']; $tabTriAff[$id] = ($commentaire['tri'].'.'.(10000000+(1*$commentaire['code'])))*1; } } // Table Tri Aff $fp = fopen($path.'/'.ucfirst($type).'Tri'.$version.'N'.$cycle.'.php', 'w'); fwrite($fp, ' $idVal) { fwrite($fp, "\t" . $id." => ".$idVal."," . "\n"); } fwrite($fp, ");" . "\n"); fclose($fp); // Table commentaires $fp = fopen($path.'/'.ucfirst($type).'Txt'.$version.'N'.$cycle.'.php', 'w'); fwrite($fp, ' $idVal) { fwrite($fp, "\t" . $id." => array(" . "\n"); foreach ($idVal as $ligne => $ligneVal) { fwrite($fp, "\t\t" . $ligne." => \"".$ligneVal."\"," . "\n"); } fwrite($fp, "\t" . ")," . "\n"); } fwrite($fp, ");" . "\n"); fclose($fp); echo "Code généré. \n"; } // --- Gestion des éléments de cache if ( $opts->tabcache) { $pathCache = APPLICATION_PATH . '/../library/Metier/Scores/Data'; // Variables $fp = fopen($pathCache . '/Variables.php','w'); fwrite($fp, "executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='TU'"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'TU' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"".str_replace('$', $item->libelle, $item->article)."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** REGIMP - RPEN */ $stmt = $conn->executeQuery("SELECT REGION AS code, 'int' AS type, NCCENR AS libelle FROM insee.regions"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'REGIMP' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); fwrite($fp, "\t'RPEN' => array(\n"); $stmt->closeCursor(); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** ZEMET */ $stmt = $conn->executeQuery("SELECT codZEMET AS code, libZEMET AS libelle, article FROM insee.insee_tabZemet WHERE anneeZemet='1994'"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'ZEMET1994' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { if( in_array(strtoupper(substr($item->libelle,0,1)),array('A','E','I','O','U')) ) { $prefix = "d'"; } else { $prefix = "de "; } fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $prefix . $item->libelle."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } $stmt = $conn->executeQuery("SELECT codZEMET AS code, libZEMET AS libelle, article FROM insee.insee_tabZemet WHERE anneeZemet='2010'"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'ZEMET2010' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { if( in_array(strtoupper(substr($item->libelle,0,1)),array('A','E','I','O','U')) ) { $prefix = "d'"; } else { $prefix = "de "; } fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $prefix . $item->libelle."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** DEPSIE */ $stmt = $conn->executeQuery("SELECT numdep AS code, libdep AS libelle FROM insee.departements"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'DEPSIE' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** LIEUACT */ $stmt = $conn->executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='LIEUACT'"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'LIEUACT' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". preg_replace('/\$1?/', $item->libelle, $item->article) ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** ACTISURF */ $stmt = $conn->executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='ACTISURF'"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'ACTISURF' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". str_replace('$', $item->libelle, $item->article) ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** ACTIVNAT */ $stmt = $conn->executeQuery("SELECT code, codeType, libelleCase, libelle, article FROM insee.insee_tabAutres WHERE zone='ACTIVNAT'"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'ACTIVNAT' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". str_replace('$', $item->libelle, $item->article) ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** FJUR - FJURINSEE - FJURRNCS*/ $stmt = $conn->executeQuery("SELECT code, libelle FROM jo.tabFJur"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'FJUR' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . str_replace('"','\"',$item->libelle) . "\", 'art'=>\"". str_replace('"','\"',$item->libelle) ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); fwrite($fp, "\t'FJURINSEE' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . str_replace('"','\"',$item->libelle) . "\", 'art'=>\"". str_replace('"','\"',$item->libelle) ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); fwrite($fp, "\t'FJURRNCS' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . str_replace('"','\"',$item->libelle) . "\", 'art'=>\"". str_replace('"','\"',$item->libelle) ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } /** APEENT - APEINSEE - APERNCS */ $stmt = $conn->executeQuery("SELECT codNaf700 AS code, libNaf700 AS libelle FROM jo.tabNaf4 UNION SELECT codNaf5 AS code, libNaf5 AS libelle FROM jo.tabNaf5"); if ($stmt->rowCount() > 0 ) { fwrite($fp, "\t'APEENT' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); fwrite($fp, "\t'APEINSEE' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); fwrite($fp, "\t'APERNCS' => array(\n"); while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t\t'".$item->code."' => array("); fwrite($fp, "'lib'=>\"" . $item->libelle . "\", 'art'=>\"". $item->libelle ."\""); fwrite($fp, "),\n"); } fwrite($fp, "\t),\n"); } fwrite($fp, ");\n"); fclose($fp); /** Taux d'inflation **/ $fp = fopen($pathCache . '/Infla.php','w'); fwrite($fp, "executeQuery("SELECT annee, infla FROM sdv1.inflation WHERE annee>1990 ORDER BY annee"); if ($stmt->rowCount() > 0 ) { while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t" . $item->annee . " => " . $item->infla . ",\n"); } } fwrite($fp, ");\n"); fclose($fp); /** Taux de rendement des actions **/ $fp = fopen($pathCache . '/RendObli.php','w'); fwrite($fp, "executeQuery("SELECT annee, txMoinsInfla FROM sdv1.txRendObli WHERE annee>1990 ORDER BY annee ASC"); if ($stmt->rowCount() > 0 ) { while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t" . $item->annee . " => " . $item->txMoinsInfla . ",\n"); } } fwrite($fp, ");\n"); fclose($fp); /** Formules **/ $fp = fopen($pathCache . '/Formules.php','w'); fwrite($fp, "executeQuery("SELECT id, libelle, formule, unite, commentaires, borneMin, borneMax, calcul, deleted FROM jo.ratios_formules WHERE deleted=0"); if ($stmt->rowCount() > 0 ) { $i = 0; while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) { fwrite($fp, "\t".$i." => array(\n"); fwrite($fp, "\t\t'id' => ".intval($item->id).",\n"); fwrite($fp, "\t\t'libelle' => \"".trim(str_replace('"','\"',$item->libelle))."\",\n"); fwrite($fp, "\t\t'commentaires' => \"".trim(str_replace('"','\"',$item->commentaires))."\",\n"); fwrite($fp, "\t\t'unite' => '".$item->unite."',\n"); fwrite($fp, "\t\t'borneMin' => '".$item->borneMin."',\n"); fwrite($fp, "\t\t'borneMax' => '".$item->borneMax."',\n"); fwrite($fp, "\t\t'formule' => '".$item->formule."',\n"); fwrite($fp, "\t),\n"); $i++; } } fwrite($fp, ");\n"); fclose($fp); }